Font Viewer: an experiment with font()

(Updated) I wrote the code below to understand better the appearance of all the fonts available via font() (which is a larger selection of fonts than the selection presented in the font picker):

--
-- Font Viewer
--
supportedOrientations(LANDSCAPE_ANY)
displayMode(STANDARD)
function setup()
    fontName = {
        "AcademyEngravedLetPlain",
        "AmericanTypewriter-CondensedLight",
        "AmericanTypewriter-Light",
        "AmericanTypewriter",
        "AmericanTypewriter-Condensed",
        "AmericanTypewriter-Bold",
        "AmericanTypewriter-CondensedBold",
     -- "AppleColorEmoji", -- Interesting chars not in range 0-255
     -- "AppleSDGothicNeo-Medium", -- For Korean chars
     -- "AppleSDGothicNeo-Bold",   -- As above
        "ArialMT",
        "Arial-ItalicMT",
        "Arial-BoldMT",
        "Arial-BoldItalicMT",
     -- "ArialHebrew",      -- For Hebrew chars
     -- "ArialHebrew-Bold", -- For Hebrew chars
     -- "BanglaSangamMN-Bold", -- Note: differs from in-app reference;
     -- "BanglaSangamMN",      -- and for Bangla chars
        "Baskerville",
        "Baskerville-Italic",
        "Baskerville-SemiBold",
        "Baskerville-SemiBoldItalic",
        "Baskerville-Bold",
        "Baskerville-BoldItalic",
        "BodoniSvtyTwoITCTT-Book",    -- Not in picker
        "BodoniSvtyTwoITCTT-BookIta",
        "BodoniSvtyTwoITCTT-Bold",
        "BodoniSvtyTwoOSITCTT-Book",
        "BodoniSvtyTwoOSITCTT-BookIt",
        "BodoniSvtyTwoOSITCTT-Bold",
        "BodoniSvtyTwoSCITCTT-Book",
        "BodoniOrnamentsITCTT",
        "BradleyHandITCTT-Bold", -- Not in picker
        "ChalkboardSE-Light",    -- Not in picker
        "ChalkboardSE-Regular",
        "ChalkboardSE-Bold",
        "Chalkduster",           -- Not in picker
        "Copperplate-Light",
        "Copperplate",
        "Copperplate-Bold",
        "Courier",
        "Courier-Oblique",
        "Courier-Bold",
        "Courier-BoldOblique",
        "CourierNewPSMT",
        "CourierNewPS-BoldMT",
        "CourierNewPS-BoldItalicMT",
        "CourierNewPS-ItalicMT",
        "DBLCDTempBlack", -- Not in picker
     -- "DevanagariSangamMN",      -- For Devanagari chars
     -- "DevanagariSangamMN-Bold", -- As above
        "Didot",
        "Didot-Italic",
        "Didot-Bold",
     -- "EuphemiaUCAS",        -- For Unified Canadian Aboriginal Syllabics
     -- "EuphemiaUCAS-Italic", -- As above
     -- "EuphemiaUCAS-Bold",   -- As above
        "Futura-Medium",
        "Futura-MediumItalic",
        "Futura-CondensedMedium",
        "Futura-CondensedExtraBold",
     -- "GeezaPro",      -- For Arabic chars
     -- "GeezaPro-Bold", -- As above
        "Georgia",
        "Georgia-Italic",
        "Georgia-Bold",
        "Georgia-BoldItalic",
        "GillSans-Light",
        "GillSans-LightItalic",
        "GillSans",
        "GillSans-Italic",
        "GillSans-Bold",
        "GillSans-BoldItalic",
     -- "GujaratiSangamMN",      -- For Gujarati chars
     -- "GujaratiSangamMN-Bold", -- For Gujarati chars
     -- "GurmukhiMN",      -- For Gurmukhi chars
     -- "GurmukhiMN-Bold", -- For Gurmukhi chars
     -- "STHeitiSC-Light",  -- For Chinese chars
     -- "STHeitiSC-Medium", -- For Chinese chars
     -- "STHeitiTC-Light",  -- For Chinese chars
     -- "STHeitiTC-Medium", -- For Chinese chars
        "Helvetica-Light",
        "Helvetica-LightOblique",
        "Helvetica",
        "Helvetica-Oblique",
        "Helvetica-Bold",
        "Helvetica-BoldOblique",
        "HelveticaNeue-UltraLight",
        "HelveticaNeue-UltraLightItalic",
        "HelveticaNeue-Light",
        "HelveticaNeue-LightItalic",
        "HelveticaNeue",
        "HelveticaNeue-Italic",
        "HelveticaNeue-Medium",
        "HelveticaNeue-Bold",
        "HelveticaNeue-BoldItalic",
        "HelveticaNeue-CondensedBold",
        "HelveticaNeue-CondensedBlack",
     -- "HiraKakuProN-W3", -- For Japanese chars
     -- "HiraKakuProN-W6", -- For Japanese chars
     -- "HiraMinProN-W3", -- For Japanese chars
     -- "HiraMinProN-W6", -- For Japanese chars
        "HoeflerText-Regular",
        "HoeflerText-Italic",
        "HoeflerText-Black",
        "HoeflerText-BlackItalic",
        "Inconsolata",
     -- "Kailasa",      -- For Tibetan chars
     -- "Kailasa-Bold", -- For Tibetan chars
     -- "KannadaSangamMN",      -- For Kannada chars
     -- "KannadaSangamMN-Bold", -- For Kannada chars
     -- "MalayalamSangamMN",      -- For Malayalam chars
     -- "MalayalamSangamMN-Bold", -- For Malayalam chars
        "Marion-Regular",
        "Marion-Italic",
        "Marion-Bold",
        "MarkerFelt-Thin",
        "MarkerFelt-Wide",
        "Noteworthy-Light",
        "Noteworthy-Bold",
        "Optima-Italic",
        "Optima-Regular",
        "Optima-Bold",
        "Optima-BoldItalic",
        "Optima-ExtraBlack",
     -- "OriyaSangamMN",      -- For Oriya chars
     -- "OriyaSangamMN-Bold", -- For Oriya chars
        "Palatino-Roman",
        "Palatino-Italic",
        "Palatino-Bold",
        "Palatino-BoldItalic",
        "Papyrus",
        "Papyrus-Condensed",
        "PartyLetPlain",  -- Not in picker
     -- "SinhalaSangamMN",      -- For Sinhala chars
     -- "SinhalaSangamMN-Bold", -- For Sinhala chars
        "SnellRoundhand",
        "SnellRoundhand-Bold",
        "SnellRoundhand-Black",
     -- "TamilSangamMN",      -- For Tamil chars
     -- "TamilSangamMN-Bold", -- For Tamil chars
     -- "TeluguSangamMN",      -- For Telugu chars
     -- "TeluguSangamMN-Bold", -- For Telugu chars
     -- "Thonburi",      -- For Thai characters
     -- "Thonburi-Bold", -- For Thai characters
        "TimesNewRomanPSMT",
        "TimesNewRomanPS-ItalicMT",
        "TimesNewRomanPS-BoldMT",
        "TimesNewRomanPS-BoldItalicMT",
        "TrebuchetMS",        -- Not in picker
        "TrebuchetMS-Italic",
        "TrebuchetMS-Bold",
        "Trebuchet-BoldItalic", -- Note: differs from in-app reference
        "Verdana",
        "Verdana-Italic",
        "Verdana-Bold",
        "Verdana-BoldItalic",
     -- "ZapfDingbatsITC", -- Interesting chars not in range 0-255
        "Zapfino"
    }
    -- Easier to select than from a single slider:
    iparameter("Block", 0, math.floor(#fontName / 10))
    iparameter("Index", 0, 9, 1)
    textMode(CENTER)
end

function draw()
    local fontIndex = math.max(1, 
        math.min(Block * 10 + Index, #fontName))
    local size
    if fontName[fontIndex] == "Zapfino" then
        size = 32  -- Zapfino is unusually large
    else
        size = 52
    end 
    background(38, 93, 85)
    fontSize(18)
    font("Inconsolata")
    fill(255)
    local title = fontIndex..": "..fontName[fontIndex]
    title = title.." (size: "..size..")"
    text(title, WIDTH/2, HEIGHT - 10)
    fontSize(size)
    font(fontName[fontIndex])
    for j = 0, 11 do
        for i = 0, 7 do
            local char = string.char(32 + j * 8 + i)
            local x = WIDTH * (i/8 + 1/16)
            local y = (HEIGHT - 50) * ((11 - j)/12 + 1/24) + 10
            text(char, x, y)
        end
    end
end

Running this code raises some questions about text() for some of the fonts.

(Updated) The questions I have are:

(1) why are some characters rendered as cropped? (I believe it is almost all of the italic, oblique or roundhand/script fonts, but also some others.) For example: in font numbers 1 (not italic), 9, 11, 15, 17, 19, 22, 29, 35, 37, 40, 41, 44, 47, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 74, 77 (not italic), 78, 79 (not italic), 80, 83, 89, 92, 95, 97, 101, 102, 103, 105, 107, 109, 111, 113, 115 and 116;

(2) is it right that the digits only in font numbers 9, 10, 62, 63, 107, 108, and 157 are rendered so small? Answer: AppleSDGothicNeo are for Korean characters, GeezaPro for Arabic, and Kailasa for Tibetan.

(3) is it right that font numbers 17 and 18 are rendered so small (even at fontSize(52))? Answer: No - the name of the font should start “Bangla” (not “Bangala”).

(4) is it right that all of font number 152 (“TrebuchetMS-BoldItalic”) is rendered so small (even at fontSize(52)) - contrast that with related fonts numbered 150 and 151? Answer: No - the name of the font should be “Trebuchet-BoldItalic” (no “MS”).

(5) the font picker suggests that font(“AppleColorEmoji”) (number 8, here) results in coloured emoji but this code suggests otherwiseAnswer: the Unicode encoding of emoji starts well after the 0-255 range; and

(6) is it right that font(“ZapfDingbatsITC”) (number 157, here) does not actually result in any dingbat characters - contrast that with “BodoniOrnamentsITCTT” (number 32, here)?Answer: the Unicode encoding of Zapf Dingbats starts well after the 0-255 range.

  1. Sounds like there is a bug in reading the font metrics for those fonts. I will have to look at it.
  2. I fixed the Trebuchet-BoldItalic reference info — good catch. I think after typing them all out I just followed the pattern of the font name without checking.