pdflib - how to Use the end of "..." when the box width is insufficient - pdflib

I want to put a long textline, such as "ABCDEFGHIJKLMN", in a fixed-size box.
//already set fontname and fontsize
p.fit_textline("ABCDEFGHIJKLMN",100,500, "boxsize={50 20} fitmethod=clip showborder");
here's the result
[ABCDEFHG]
but i expect it like this
[ABCD...]

you can solve this with Textflow. A sample implementation is located in the PDFlib cookbook:
https://www.pdflib.com/pdflib-cookbook/textflow/continue_note_after_text/
The trick is, that you leave at the end of the box a space with createlastindent={rightindent=" + textwidth + "}. The space of the textwidth is the length of the "...", which you can determine with p.info_textline() before.

Related

Incorrect display of TEXT in SVG

The code that generates SVG:
"<text x=\"" + (Width / 2) + "\" y=\"18\" width=\"30\" text-anchor=\"middle\" font-weight=\"Bold\" font-family=\"Simplex\" font-size=\"7\">" + "123" + "</text>"
The code is looped so it displays repeatedly
What's wrong with this text?
Conclusions:
centers the first digit
other elements start at the beginning of the element
When I remove the text-anchor, it changes a little but it still displays incorrectly
The problem is probably division by 2 (Width / 2)
You get a floating point value, which means that the separator is , instead of . in String Value
Use:
(Width / 2).ToString("0.00", CultureInfo.InvariantCulture)

PDFlib - "leading" option of create_textflow

I'm trying to figure out how to add line spacing without adding spacing above the very first line of textflow.
This code:
$text = 'For more information about the Giant Wing Paper Plane see ' .
'our Web site <underline=true>www.kraxi-systems.com' .
'the Giant Wing in a thunderstorm as soon as possible.';
$optlist = 'fontname=Helvetica fontsize=12 encoding=unicode leading=400%';
$tf = $p->create_textflow($text, $optlist);
$result = $p->fit_textflow($tf, 28.346, 28.346, 400, 700, 'fitmethod=nofit');
$p->delete_textflow($tf);
results in:
All is good.
Next, I'm increasing the leading option to 400% as:
$optlist = 'fontname=Helvetica fontsize=12 encoding=unicode leading=400%';
And that gives me this:
Question:
How do I keep first paragraph line at the original position and only increase line spacing AFTER it?
checkout the "firstlinedist" option. The default is leading, but you might set this to "ascender" or "capheigt" or any other value.
Please see PDFlib 9.2 API reference, chapter 5.2, table 5.12 for more details.

Set cursor/selection for contenteditable div

Setting focus is simple enough: node.focus(). I've had limited success looking at other answers. I can set the cursor at either the beginning or end, or I can select the whole contents with this code in chrome:
// if start==0 means the beginning, start===1 means the end
function setSelection(node, start, length) {
var range = document.createRange();
range.setStart(node, start);
range.setEnd(node, length);
//range.collapse(true);
var selection = getSelection()
selection.removeAllRanges();
selection.addRange(range);
}
So the question is: how can I set the cursor more granularly, say at character 2. Also, how can I set the selection, for example from character 2 to character 5?
MDN tells me that Range.setStart has different behavior for Text, Comment, or CDATASection nodes than other nodes. If I could get setStart to treat a div like a Text node, I think my problem might be solved.
Anyone have any ideas?

How do I set up my multiline wordWrap TextField to automatically resize its width when height is set?

I want to create a textfield extension that:
When width is set, automatically resize height by the content of text. Easy done by autosize left, word wrap true, multiline true.
When height is set, automatically resize width by the content of text. Here is my problem.
When both width and height set aren't a case I am interested in.
I've tried several things off the internet, I am stumped.
General solution is impossible, as if the text field contains too many newlines to display within a given height, no matter what width you assign, the text field will be unable to display all the lines. Partial solution is presented by greetification, but it lacks some features one should be aware of. First, no matter what you do, you should not set height to value less than font height, or the text field will not be able to display a single line. Second, if wordWrap is set to false, and multiline to true, the resultant textWidth is the largest desirable width for your text field, so if you adjust the width like greetification advises, stop once you reach the recorded textWidth, as further increases are pointless.
function setHeight(newHeight:Number):void {
var tw:Number;
var th:Number;
if (myTextField.wordwrap) {
myTextField.wordwrap=false;
tw=myTextField.textWidth;
th=myTextField.textHeight;
myTextField.wordwrap=true;
} else {
tw=myTextField.textWidth;
th=myTextField.textHeight;
}
if (newHeight<th) newHeight=th+2; // as below
myTextField.height = newHeight;
while((myTextField.textHeight > myTextField.height)&&(myTextField.width<tw)) {
myTextField.width += 100;
}
if (myTextField.width>tw) myTextField.width=tw+2; // "2" depends on text format
// and other properties, so either play with it or assume a number big enough
}
Not the most elegant solution, but it should work:
function setHeight(newHeight:Number):void {
myTextField.height = newHeight;
while(myTextField.textHeight > myTextField.height) {
myTextField.width += 100;
}
}

show tinymce contents in a div with flexible though maximum height

When using an editor like tinymce, how could i limit the height of the text a user enters so it doesn't use more space on the webpage than i want it to?
There are 2 things that i want some advise on:
In the editor:
The user enters text in a tinymce editor, he could set a text to font-size say 80px which would use up more space than a normal letter. So it's not the amount of text that i care about it's the height of the total.
In the webpage:
I don't want to give them more than say 200px worth of text on the page. But if they enter just 1 line of text with a small font-size i don't want to show a 200px space. So the height has to be flexible but with a maximum.
I know this isn't exact science but the goal here is to prevent the user from messing up the page.
To solve a similar issue i wrote the following function (placed inside an own tinymce plugin). You will need to add a variable for the maximum case and maybe tweak it a bit, but i hope this code will put you into the right direction
// this function will adjust the editors iframe height to fit in the editors content perfectly
resizeIframe: function(editor) {
var frameid = frameid ? frameid :editor.id+'_ifr';
var currentfr=document.getElementById(frameid);
if (currentfr && !window.opera){
currentfr.style.display="block";
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight + 26;
}
else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
}
styles = currentfr.getAttribute('style').split(';');
for (var i=0; i<styles.length; i++) {
if ( styles[i].search('height:') ==1 ){
styles.splice(i,1);
break;
}
};
currentfr.setAttribute('style', styles.join(';'));
}
},