We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How would you do to write bold text when using text(String,int,int)
?
Would I need to change the font to get the effect? And is it possible to know what is the current font being used by Processing?
Kf
Answers
BUT:
If you want to treat any part of a text string differently, you can simulate this by breaking your one call to
text()
up into multipletext()
calls using the bricklaying method recently discussed in another thread: https://forum.processing.org/two/discussion/comment/80759/#Comment_80759So, you print your words or phrases one at a time, and when you get to that word or phrase you want to be bold, you either change the font to a bold version of the font or you do pseudo-bold -- for example by drawing the word several times with 1px offsets.
The easiest way is to set the font explicitly at the start of your sketch -- then you know what font it is. See the Typography tutorial for details, which also explains how to find the list of currently available fonts for loading: https://processing.org/tutorials/typography/
Thxs @jeremydouglass. Setting the font works for me as my text messages are handled by different text calls.
Kf
@jeremydouglass Do you have any idea how bold actually works in the fonts? So far, every font I've seen has a bold and an italics option. Is there some simple algorithm for it?
One can generate bolder-looking text with an algorithm, but font weights like bold are also carefully designed by typographers -- there is an art to it. Some parts get thicker, other parts stay the same, depending on the letter, the kind of curve, and the style of font etc.
For more info see:
Also, the Processing tutorial on Typography!
Typographers have designed multiple types for so many thousands of different fonts. Impressive.
I made a small mark up language here:
<
and after>
, but never inside<
and>
.you can use
Hope this helps.
Best, Chrisir ;-)
Keywords: bricklaying, markup, mark up language, formatting text
Thanks for sharing this, @Chrisr -- how great!
This could easily be easily become a library for marking up font color and style in a sketch. I could also imagine it being extended in the future to support sizes, e.g.
<24> large text </24>
.One note about your demo sketch above: I'm on a macOS 10.12, and I don't have "Arial Bold" or "Arial Italic" installed, so that part of the sketch does nothing. These are the Arial fonts on my system:
To get your sketch working quickly, I changed these lines to Courier:
I imagine this could be made more robust by using a Processing built-in font (?), or by checking the font list for multiple candidates that might appear on Mac / Linux / Windows systems and then loading one that is available. (Or, of course, by bundling a set of built-in fonts with the library / sketch.)
Thanks a lot! Yes, I am on Win 10 system.
Also I didn't take into account a italic bold combination...
;-)
@Chrisir
I agree with @jeremydouglass, you should consider encapsulating this in a library. Really neat effort and could potentially replaced or expand the simple text() function implemented within the PDE.
Kf
I like the custom format for defining specific colors inline:
<Col255,0,0>
HTML-like?
Another way might be to implement just a few full tags that are standardized to look just like HTML -- including
<bold>
,<strong>
,<em>
,<i>
.Advantages:
there are two familiar syntaxes for html text coloring. This would require implementing keywords, and isn't as compact, but is very readable.
Downsides:
Might be misleading.
Markdown-like?
An alternative approach would be to implement simple Markdown rules for bold and italics:
Advantages:
Very easy to write, familiar (the forum uses it!), cross-compatible with thousands of software systems.
Downsides:
*
and_
characters.<col >
method.nice ideas! I don't have the time at the moment
What is you make the disadvantage an advantage @jeremydouglas?
Kf
But anyone feel free to use my code. I don’t know how to make a library anyway