Is there a way to make a fragment of text within a line bold in nodejs pdfkit? - node.js

Node-pdfkit http://pdfkit.org/index.html
I am using nodejs pdfkit to generate a pdf. I want to be able to bold or italic individual words in a line. It looks like pdfkit doesn't support this, so I was wondering if anyone had done something similar?
What would be really useful is to call the doc.text function, but have the document retain it's x position, so that I could do the following.
doc.text('some words then ');
doc.font('Helvetica-Oblique');
doc.text('italic');
doc.font('Helvetica');
doc.text(' then the remaining words');
and see the output:
some words then italic then the remaining words.
Right now it's outputting one line per text function.
Anyone know a good way to do this?

This feature was added by ej4 in this pull request https://github.com/devongovett/pdfkit/pull/60
It hasn't been merged in to the main project yet, so I ended up forking pdfkit myself, and including ej4s changes and a few of my own.
The basic result is that the changes make it possible to add
continued: true
to the options object. Pdfkit then remembers the caret position and returns you to that position for the next line of text.

Please see: Can I mix font weights in the same paragraph when using pdfkit?
pdf.text('Hello ', LEFT, 200, {
//here it is,
lineBreak : false
}).font(bold).text('World!');

Related

How can I change the font sizing within multiple lines of a string in Lua? (WoW Lua Question)

I am currently beginning to write functions for WoW WeakAura addons that use the WoW Lua in order to create the addon. I am trying to change the fonts within the printed string so that I have a Header essentially.
The code is essentially as follows:
return string.format("|cFFFFFFFFHeader Text|r\nRegular Text|r\nMore Regular Text|r\nEven More Regular Text")
The current printing returns all of the text the same size, but I just want to make the "Header Text" a size larger. I've found how to modify the colors, but I have yet to find anything similar for font size. Can someone assist?

Reverse Colors on Google Doc for printing

There may be a simple answer but is there a quick way to reverse colors on google docs, just for printing?
I like having our background of the doc blue and the text white for the view mode on the screen, but if someone goes to print that is a lot of blue ink, is there a fast way to change it --- not copying and pasting into a new doc?
Thanks!
Unfortunately Google Docs doesn't have the option of reversing the colors in the document when trying to print it.
What you can do instead is to make a copy of the original document and then modify it to your liking so it is suitable for printing. In this way you will have two copies of the document - one for the viewing mode and one for the printing mode.
go to format -> images -> image options -> recolor select negative

How to show whitespace for given scope in a Sublime Text color scheme

Is there any way to set white space visible for a given scope?
I'm working on modifying a color scheme to suite my liking and would like to be able to show spaces within a given scope. I haven't seen anything suggesting it's possible within the color-scheme documentation on Sublime's website.
For my specific case, and I imagine there's other useful cases, I'm working with Markdown and want to highlight a double-space line-break. I'm able to set the background, but this doesn't look quite right. I'm hoping to be able to make whitespace visible for this small scope and change the foreground color to make it stick out.
The short answer to your question is no; or rather, Yes, but only in the way that you've already discovered.
Color schemes can only apply foreground/background colors to scopes as well as bold/italic font weights. So assuming that there is a specific scope detected by the syntax you're using that is used for the things you're trying to highlight, the only thing the color scheme can do is alter the background color to make them visible.
The only thing that can render white space natively is the draw_white_space setting, which at the moment only allows you to turn it off everywhere, turn it on everywhere, or turn it on only for selected text. In this case that doesn't really help.
There are possibilities for something like this in the plugin realm though (these examples can be tested by opening the Sublime console with View > Show Console or Ctrl+` and entering the code in there; they also assume that you're using the default Markdown syntax):
view.add_regions("whitespace", view.find_by_selector("punctuation.definition.hard-line-break.markdown"), "comment", flags=sublime.DRAW_NO_FILL)
This will cause all of the hard line breaks to be outlined as if they were find results; the color is selected by the scope (which is comment here); that would make them visible without making the whole character position have a background color.
view.add_regions("whitespace", view.find_by_selector("punctuation.definition.hard-line-break.markdown"), "comment", "dot", flags=sublime.HIDDEN)
This will add a dot (colored as a comment) in the gutter for lines that end with this scope; you can also combine this with the previous example to outline them and also call attention in the gutter.
style = '<style>.w { color: darkgray; }</style>'
content = '<body id="whitespace">' + style + '<span class="w">ยทยท</span></body>'
phantom_set = sublime.PhantomSet(view, "whitespace")
phantoms = [sublime.Phantom(r, content, sublime.LAYOUT_INLINE) for r in view.find_by_selector("punctuation.definition.hard-line-break.markdown")]
phantom_set.update(phantoms)
This uses Sublime's ability to apply inline HTML phantoms into the document in order to inject a small inline sequence of two unicode center dots immediately between the actual whitespace and the text that comes before it. Here the content can be what you like if you can generate the appropriate HTML; we're just applying a color to the text in this example.
A potential downside here is that the characters you see in the inline HTML aren't considered to be part of the document flow; the cursor will skip over them in one chunk, and they're followed by the actual whitespace.
The result of this example looks like this:
Going the plugin route, you'd need an event handler like on_load() to apply these when a file is loaded and on_modified() to re-update them after modifications are made to the buffer. There may or may not be a package that already exists that has implemented this.

React-Native Change Text With setNativeProps

Has anyone figured out a way to dynamically mutate text on the screen without triggering a render?
A large part of my screen utilizes setNativeProps for moving parts, meaning that the animations become lagged despite using shouldComponentUpdate. I would like to use the Text tag instead of the TextInput tag workaround suggested in this post for stylistic reasons.
Best case scenario is a workaround that involves setNaiveProps as it would follow the pattern of the rest of the screen; however, I currently plan to render all the numbers 0-9 on the screen an move them into place at the moment, so any help would be greatly appreciated!
As it turns out, you can actually format TextInputs the same exact way as Text elements (from what I have tested). For placing text horizontally, you have to set the width (something I had trouble with before). For those still interested in the original question however, you can nest TextInputs inside of a Text Element (one per text element because there is no justification and it automatically places them in a row). Styling applied to the Text Element will apply to the TextInput.

NSAttributedString: wrapping + truncation

I have a view that draws multicolored text inside UITableViewCell. To draw multicolored text I'm using NSAttributedString However, I would like to make it so that if the text is too long to fit into the view, the last visible line is truncated to display an ellipsis at its end.
Obviously this is very easy to do when drawing only a single line, as you can just set
kCTLineBreakByTruncatingTail for the line break mode of the paragraph style. The problem is that I want my text to wrap to fill the rectangle, and then only have the last line truncated with an ellipsis - setting the line break mode confines the whole text to one line.
Does anybody have any ideas of how I would go about this?
Many thanks in advance for any suggestions,
JC.
Create your CTFrame from your CTFrameSetter with the rectangle of your UITableViewCell. Then, you can get all the CTLines of your CTFrame and determine when they will cut off. To swap out the ellipsis, you could keep that drawn with a separate CTFrame and draw it over the overflowing text on the last line.
You can find working code here: https://stackoverflow.com/a/14612598/473067
It's a similar approach to what Heath suggested. But then all wrapped up in a shiny package.
Well, to activate text truncating in UILabel, you should re-set lineBreakMode parameter to NSLineBreakByTruncatingTail after setting attributedText.
textLabel.attributedText = attributedText;
textLabel.lineBreakMode = NSLineBreakByTruncatingTail;

Resources