Date: | Wed, 18 Jan 2023 23:06:40 -0800 |
From: | Bret Victor |
Subject: | Re: fonts and styled text |
This is some text where I
have added manually newlines
because my text editor
doesn't wrap lines.
Paragraphs are separated by
a blank line.
-- Pretend this is a very long comment in your program.
-- Pretend this is a
-- very long comment
-- in your program.
On Jan 18, 2023, at 2:51 PM, Luke Iannini <****************> wrote:Radical!! I will check into adding a font deletion API to NanoVGI was gonna bundle this up in a January Update but since it might be immediately useful, Realtalk can now rasterize PDFs via Ghostscript:<IMG_0205.jpeg>I haven't merged up yet since I'm still in the middle of things but you should be able to just grab "Browsing PDFs" and "PDF to image" from Print Kit safely!Relevant wishes/whens are:Wish (you) shows PDF (pdf_url) with page number (page_number). -- The basic wish. You can also pass DPI to force a DPI rather than the coarse auto-estimateWish (you) shows PDF (pdf_url) thumbnails with rows (3) columns (4). -- thumbnails are boxes, so you can use View PDF page (42572) to point at them and view full sizeWish (you) browses PDF (pdf_url). -- Point a keyboard at this to page through the PDF with the arrow keys. Also takes DPI. Hold alt/ctrl/shift to jump forward by *10 (stacks with more modifiers)When PDF /pdf/ has page count /page_count/: -- Get the number of pages in a PDFI was hoping to get the per-page text out too but that Ghostscript command seems buggy, hopefully soon!(and I guess we'll probably parse and render PDF ourselves someday but this will still be handy to check that Ghostscript renders our PDFs accurately!)On Jan 17, 2023, at 11:47 PM, Bret Victor <****************> wrote:We can't unload fonts, so once you wish for a font, you're stuck with it.To clarify -- once you wish for a font, it's available until the area restarts. We're not installing anything persistent. A page/kit should actively wish for the fonts it wants to use, in case we are someday able to unload fonts.On Jan 17, 2023, at 7:52 PM, Bret Victor <****************> wrote:I had been printing captions for the progress report using Pages on the Mac, mostly because I wanted to use Avenir and Realtalk couldn't embed fonts into PDFs. Yesterday I was roadblocked by a pair of back-to-back bugs in Pages, and in my unquenchable rage I ditched the laptop and updated Realtalk's text and font capabilities. Further reports forthcoming if I actually succeed in turning Realtalk into a page layout wonderland.Adding fontsHere's how to make a non-default font available:Wish font face "Avenir" uses font file (Ref "8e8bdd3a55a1b0ea022e25a54a7795e8.ttf").Thereafter, you can measure and draw with it just like any font.Wish (you) is labelled "The worst." with font face "Avenir".We can't unload fonts, so once you wish for a font, you're stuck with it.If you want to see all the fonts that are currently available:When font face /face/ is available:The default fonts are in "Base fonts":Wish font face "Helvetica" uses font file (Ref "2ce7bccbe71ea34eeb77b96f72ac56a9.ttf") with required (true).Wish font face "Helvetica I" uses font file (Ref "1abbd4cf2d371faa8e43d4e989a7c492.ttf") with required (true).(etc)("required" ensures that the font is downloaded before we create the rendering context, so there are no missing-font surprises.)Printing with fontsDraw on a proof with your new font, then print it or convert to PDF. It just works.Nonstandard fonts are embedded in the PDF. They are not subsetted; the whole font is just dropped in. They're usually pretty small (e.g. Avenir is 53K).Rescaled fontsIf you ever noticed that our "Serif" font ("Goudy Bookletter 1911"?!) seemed too small, it's because NanoVG was scaling fonts wrong. That's been fixed, so Serif (and others) renders at the right height and is correctly printable. The fix ended up being simple, but only after an overlong descent into the font metrics abyss, where only madness reigns.(Details for future reference: unitsPerEm from the font's "head" table is the proper way to scale from glyph units to pixels/inches, but NanoVG was scaling by (ascender - descender) from the "hhea" table. (ascender - descender) == unitsPerEm for many fonts, but not all of them. Probably nobody ever noticed because we're the first one to try to get NanoVG's output to match PDF.)Styled rangesI need my italics. We can now draw text with styled ranges.Wish (you) draws "text" "The worst." withranges { { start_pos=5, end_pos=9, font_face="Helvetica I", color="yellow" } }.A range can specify font_face, font_size, and/or color, and they will override the text's base settings.<IMG_695701212.jpeg>Styled markupSometimes you want to use markup instead of ranges.Wish (you) draws "text" "The <i>worst</i>." withmarkup { i = { font_face="Helvetica I", color="yellow" } }.You can use whatever HTML-like tags you want, and provide a dictionary from tag name to style. Tags cannot overlap. There are default styles for some common tags ("i", "b", "em", "strong").local text = "I'd <i>like</i> to <big>tell</big> you <mono>about</mono> my <green>problems</green>."local styles = {big ={ font_face="Serif", font_size=0.7, color="pink" },mono ={ font_face="Mono B", font_size=0.5, color="orange" },green={ color="green", font_face="Helvetica B" }}Wish (you) draws "text" (text) with width (2.5) font size (0.3) background "blue" markup (styles).<IMG_695705322.jpeg>If you want to convert from markup to ranges for some reason, you can use the functionlocal text, ranges = text_and_ranges_for_markup(html, styles)