FontView

-- By Gregory Thomas

displayMode(OVERLAY)

function setup()
    
    saveProjectInfo("Description","by Gregory Thomas")
    saveProjectInfo("Author","Gregory Thomas")
    vitesse=4 ; dx=0 ; dy=0
    
    tab = {
    {"04b_21"},
    {"3X5"},
    {"5x8-LCD-HD44780U-A02"},
    {"Abduction"},
    {"A bit sketchy"},
    {"AcademyEngravedLetPlain"},
    {"Advent"},
    {"Airstream"},
    {"Aladdin"},
    {"Alias"},
    {"AmericanTypewriter"},
    {"Amstrad CPC464"},
    {"AppleColorEmoji"},
    {"ArialMT"},
    {"Bad Striped"},
    {"Badaboom bb"},
    {"Baskerville"},
    {"Belladone"},
    {"Blackjack"},
    {"BodoniOrnamentsITCTT"},
    {"BonvenoCF"},
    {"BradleyHandITCTT-Bold"},
    {"Brankovic"},
    {"Brillante St"},
    {"Brush Script MT"},
    {"Caprica Sans Personal Use"},
    {"CFB"},
    {"Chalkduster"},
    {"Children Stories"},
    {"Chunkfive"},
    {"Cloud Control"},
    {"Cochin"},
    {"ColunaSketch-CondensedBold"},
    {"Comfortaa"},
    {"Comic Cover"},
    {"Comic Sans MS"},
    {"Controller"},
    {"Cookie"},
    {"Copperplate"},
    {"Courier"},
    {"CrackMan"},
    {"CranberryBlues"},
    {"CRU Sarawut 57"},
    {"Damascus"},
    {"Delusion"},
    {"Depraved"},
    {"DF-GameOver"},
    {"Didot"},
    {"DiscoFresca"},
    {"Discovery"},
    {"Diskoteque"},
    {"Dollar Bill"},
    {"DotLine"},
    {"DreamStencil"},
    {"Dubtronic-Solid"},
    {"Dubtronic Inline"},
    {"Easy 3D"},
    {"Even"},
    {"Eight One"},
    {"EnergyDrink"},
    {"Famirids"},
    {"Farah"},
    {"Feast of flesh bb"},
    {"Fill Me With Color"},
    {"FiveDollar"},
    {"Fopi Rush"},
    {"FOREST THING"},
    {"Fracta"},
    {"Fracta-Italic"},
    {"FrangiaFour"},
    {"FStein"},
    {"Futura-Medium"},
    {"GaelleNumber4"},
    {"Gameover"},
    {"GAME PLAYER"},
    {"GeezaPro"},
    {"Georgia"},
    {"GillSans"},
    {"Gubblebum"},
    {"Gubblebum-BlacknBlocky"},
    {"Helleplus32"},
    {"Helvetica"},
    {"HenryMorganHand"},
    {"HighLevel"},
    {"Hypersober"},
    {"Hp48keys"},
    {"Hp48gos1"},
    {"Hp48gos2"},
    {"Hp48gos3"},
    {"HouseM.D."},
    {"Hppt"},
    {"Imagica"},
    {"Infected"},
    {"Influence"},
    {"Iomanoid"},
    {"Jazz Zebra"},
    {"Jrhand"},
    {"Joystix"},
    {"K141"},
    {"Keyboard Warrior"},
    {"LemonChicken"},
    {"LesEtoiles"},
    {"LifeCraft"},
    {"LoveScratch"},
    {"Madonna"},
    {"Marion"},
    {"Mastermind"},
    {"MATRIX"},
    {"MegaMan 2"},
    {"Menlo"},
    {"Merkur"},
    {"MixShaded"},
    {"MobileFont"},
    {"Molten"},
    {"Namco Regular"},
    {"NeonTech"},
    {"Neverwinter"},
    {"Noteworthy-Bold"},
    {"ODEON-DROP"},
    {"Only When I Do Fonts"},
    {"OpenDyslexic"},
    {"Pancakeslims"},
    {"Papyrus"},
    {"PartyLetPlain"},
    {"Perfect Dark Zero"},
    {"PetMe"},
    {"PitStop"},
    {"PlagueDeath"},
    {"Plateaux"},
    {"Playbill"},
    {"Poison Apple DEMO"},
    {"Pristina"},
    {"Puppeteer"},
    {"QuickSales"},
    {"Qxdigitalninja"},
    {"Ready Steady Go"},
    {"Rio Frescata Demo"},
    {"RopeMF"},
    {"SaltyBeach"},
    {"SavoyeLetPlain"},
    {"ShadowedBlack"},
    {"Skinny Zebra"},
    {"Standard0753"},
    {"StripeAttack"},
    {"Superclarendon"},
    {"Tassel"},
    {"Techno Funk"},
    {"Tetris"},
    {"Texas LED"},
    {"Thonburi"},
    {"Tifont"},
    {"TimesNewRomanPSMT"},
    {"Tiza"},
    {"Trashco"},
    {"TrebuchetMS"},
    {"Tron"},
    {"Turok"},
    {"Ultravioleta"},
    {"Unek"},
    {"Unreal Tournament"},
    {"UpperEastSide"},
    {"Verdana"},
    {"WalkwayBlack"},
    {"XeroTypique"},
    {"ZapfDingbatsITC" },
    {"Zapfino"},
    {"Zrnic"}
    }
    
    parameter.color("couleur_background",color(105, 71, 87, 255))
    parameter.color("couleur_fonte",color(203, 135, 98, 255))
    parameter.color("couleur_ombre",color(73, 46, 198, 255))
    parameter.boolean("ombre",true)
    parameter.integer("epaisseur_ombre",1,9,4)
    parameter.integer("exemple",1,4,1)
    parameter.text("texte_perso")
    
end

function draw()
    
    background(couleur_background)
    fontSize(50)
    fill(couleur_fonte)
    
    for a=1, #tab do
        if exemple==1 then
            str=tab[a][1]
        elseif exemple==2 then
            str="abcdefghIjklmnopqrstuvwxyz"
        elseif exemple==3 then
            str="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        elseif exemple==4 then
            str=texte_perso
        end
        font(tab[a][1])
        if ombre then
          fill(couleur_ombre)
            for i=1,epaisseur_ombre do 
                text(str,WIDTH/2+dx+i,HEIGHT-a*70+dy-i)
            end
        end
        fill(couleur_fonte)
        text(str,WIDTH/2+dx,HEIGHT-a*70+dy)   
    end
    
end

function touched(t)
    if t.state==MOVING then
        dy=dy+t.deltaY*vitesse
        --dx=dx+t.deltaX*vitesse
    end
end

This program allows you to view the fonts of characters.
you have to adapt in the name of your personal fonts.
I think it was interesting to include the two versions of gradientext
created by techdojo and diablo76. Thanks for sharing.

@hpsoft - glad you liked it. I’m curious to try this out and see what get’s rendered. I’d like to include custom fonts if possible in my apps.

Hmm - when I run the above software on my stock iPad3 I find that the following strings when passed to the font() function actually allow me to render text in “other” fonts (ie one’s not listed in the font previewer - ok a couple of them are but definitely not all of them)

    tab = {
    {"AcademyEngravedLetPlain"},
    {"AmericanTypewriter"},
    {"AppleColorEmoji"},
    {"ArialMT"},
    {"Baskerville"},
    {"BodoniOrnamentsITCTT"},
    {"BradleyHandITCTT-Bold"},
    {"Chalkduster"},
    {"Cochin"},
    {"Copperplate"},
    {"Courier"},
    {"Damascus"},
    {"Didot"},
    {"Farah"},
    {"Futura-Medium"},
    {"GeezaPro"},
    {"Georgia"},
    {"GillSans"},
    {"Helvetica"},
    {"Marion"},
    {"Menlo"},
    {"Noteworthy-Bold"},
    {"Papyrus"},
    {"PartyLetPlain"},
    {"Superclarendon"},
    {"Thonburi"},
    {"TimesNewRomanPSMT"},
    {"TrebuchetMS"},
    {"Verdana"},
    {"ZapfDingbatsITC" },
    {"Zapfino"},
    }

Is this just a by product of how the Codea font functions work in that we can actually use any installed Apple fonts, AND more importantly does it mean that we could actually use a custom font in our exported apps by including the .ttf / .otf file in the project and then registering it with the system at runtime???

Thinking about it - I know Chalkduster is a font that I’ve used on some keynote presentations, so I wonder if that’s installed as part of keynote, can anyone who HASN’T got numbers, pages or keynote installed on their machine run the code and see if they get similar results


-- 

displayMode(OVERLAY)

function setup()

    vitesse=4 ; dx=0 ; dy=0
    
    tab = {
    {"04b_21"},
    {"3X5"},
    {"5x8-LCD-HD44780U-A02"},
    {"Abduction"},
    {"A bit sketchy"},
    {"AcademyEngravedLetPlain"},
    {"Advent"},
    {"Airstream"},
    {"Aladdin"},
    {"Alias"},
    {"AmericanTypewriter"},
    {"Amstrad CPC464"},
    {"AppleColorEmoji"},
    {"ArialMT"},
    {"Bad Striped"},
    {"Badaboom bb"},
    {"Baskerville"},
    {"Belladone"},
    {"Blackjack"},
    {"BodoniOrnamentsITCTT"},
    {"BonvenoCF"},
    {"BradleyHandITCTT-Bold"},
    {"Brankovic"},
    {"Brillante St"},
    {"Brush Script MT"},
    {"Caprica Sans Personal Use"},
    {"CFB"},
    {"Chalkduster"},
    {"Children Stories"},
    {"Chunkfive"},
    {"Cloud Control"},
    {"Cochin"},
    {"ColunaSketch-CondensedBold"},
    {"Comfortaa"},
    {"Comic Cover"},
    {"Comic Sans MS"},
    {"Controller"},
    {"Cookie"},
    {"Copperplate"},
    {"Courier"},
    {"CrackMan"},
    {"CranberryBlues"},
    {"CRU Sarawut 57"},
    {"Damascus"},
    {"Delusion"},
    {"Depraved"},
    {"DF-GameOver"},
    {"Didot"},
    {"DiscoFresca"},
    {"Discovery"},
    {"Diskoteque"},
    {"Dollar Bill"},
    {"DotLine"},
    {"DreamStencil"},
    {"Dubtronic-Solid"},
    {"Dubtronic Inline"},
    {"Easy 3D"},
    {"Even"},
    {"Eight One"},
    {"EnergyDrink"},
    {"Famirids"},
    {"Farah"},
    {"Feast of flesh bb"},
    {"Fill Me With Color"},
    {"FiveDollar"},
    {"Fopi Rush"},
    {"FOREST THING"},
    {"Fracta"},
    {"Fracta-Italic"},
    {"FrangiaFour"},
    {"FStein"},
    {"Futura-Medium"},
    {"GaelleNumber4"},
    {"Gameover"},
    {"GAME PLAYER"},
    {"GeezaPro"},
    {"Georgia"},
    {"GillSans"},
    {"Gubblebum"},
    {"Gubblebum-BlacknBlocky"},
    {"Helleplus32"},
    {"Helvetica"},
    {"HenryMorganHand"},
    {"HighLevel"},
    {"Hypersober"},
    {"Hp48keys"},
    {"Hp48gos1"},
    {"Hp48gos2"},
    {"Hp48gos3"},
    {"HouseM.D."},
    {"Hppt"},
    {"Imagica"},
    {"Infected"},
    {"Influence"},
    {"Iomanoid"},
    {"Jazz Zebra"},
    {"Jrhand"},
    {"Joystix"},
    {"K141"},
    {"Keyboard Warrior"},
    {"LemonChicken"},
    {"LesEtoiles"},
    {"LifeCraft"},
    {"LoveScratch"},
    {"Madonna"},
    {"Marion"},
    {"Mastermind"},
    {"MATRIX"},
    {"MegaMan 2"},
    {"Menlo"},
    {"Merkur"},
    {"MixShaded"},
    {"MobileFont"},
    {"Molten"},
    {"Namco Regular"},
    {"NeonTech"},
    {"Neverwinter"},
    {"Noteworthy-Bold"},
    {"ODEON-DROP"},
    {"Only When I Do Fonts"},
    {"OpenDyslexic"},
    {"Pancakeslims"},
    {"Papyrus"},
    {"PartyLetPlain"},
    {"Perfect Dark Zero"},
    {"PetMe"},
    {"PitStop"},
    {"PlagueDeath"},
    {"Plateaux"},
    {"Playbill"},
    {"Poison Apple DEMO"},
    {"Pristina"},
    {"Puppeteer"},
    {"QuickSales"},
    {"Qxdigitalninja"},
    {"Ready Steady Go"},
    {"Rio Frescata Demo"},
    {"RopeMF"},
    {"SaltyBeach"},
    {"SavoyeLetPlain"},
    {"ShadowedBlack"},
    {"Skinny Zebra"},
    {"Standard0753"},
    {"StripeAttack"},
    {"Superclarendon"},
    {"Tassel"},
    {"Techno Funk"},
    {"Tetris"},
    {"Texas LED"},
    {"Thonburi"},
    {"Tifont"},
    {"TimesNewRomanPSMT"},
    {"Tiza"},
    {"Trashco"},
    {"TrebuchetMS"},
    {"Tron"},
    {"Turok"},
    {"Ultravioleta"},
    {"Unek"},
    {"Unreal Tournament"},
    {"UpperEastSide"},
    {"Verdana"},
    {"WalkwayBlack"},
    {"XeroTypique"},
    {"ZapfDingbatsITC" },
    {"Zapfino"},
    {"Zrnic"}
    }
    
    parameter.integer("taille_font",8,80,50)
    parameter.integer("mode",1,3,1)
    parameter.color("couleur_debut",color(0,255,0))
    -- color(23, 234, 456) -- color(255, 255, 255)
    parameter.color("couleur_fin",color(0,0,255))
    -- color(34, 67, 89) -- color(255, 0, 0)
    parameter.color("couleur_background",color(105, 71, 87))
    parameter.color("couleur_fonte",color(203, 135, 98))
    parameter.color("couleur_ombre",color(73, 46, 198))
    parameter.boolean("ombre",false)
    parameter.integer("epaisseur_ombre",1,9,4)
    parameter.integer("exemple",1,4,1)
    parameter.text("texte_perso")
    
end

function draw()
    
    background(couleur_background) ; fontSize(taille_font) ; fill(couleur_fonte)
    
    for a=1, #tab do
        if exemple==1 then str=tab[a][1]
        elseif exemple==2 then str="abcdefghIjklmnopqrstuvwxyz"
        elseif exemple==3 then str="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        elseif exemple==4 then str=texte_perso
        end
        font(tab[a][1])
        if ombre then
          fill(couleur_ombre)
            for i=1,epaisseur_ombre do
                x=WIDTH/2+dx+i ; y=HEIGHT-a*70+dy-i
                if mode==1 then text(str,x,y) end
            end
        end
        fill(couleur_fonte)
        x=WIDTH/2+dx ; y=HEIGHT-a*70+dy
        if mode==1 then text(str,x,y)
        elseif mode==2 then
            w,h=textSize(str) ; x=(WIDTH/2)-(w/2)+dx
            texte=GradientText(x,y,str,couleur_debut,couleur_fin,taille_font)
            texte:draw()
        elseif mode==3 then
            fontSize(50)
            -- Create an image of the text
            txtImg = image(textSize(str))
            setContext(txtImg)
            fill(255); text(str,0,0)
            setContext()
            -- Create a mesh with the image as a texture
            local w,h   = txtImg.width, txtImg.height
            local lx,ly = 50, 300
            local c1 = color(255,0,0)
            local c2 = color(0,255,0)
            local c3 = color(0,0,255)
            local c4 = color(255,255,0)
            txtMesh = mesh()
            txtMesh.vertices  = { vec2(lx,ly),  vec2(lx+w,ly), vec2(lx+w,ly+h),
                                  vec2(lx,ly),  vec2(lx+w,ly+h), vec2(lx,ly+h)}
            txtMesh.colors    = {c3,c3,c1, c3,c1,c1 }
            txtMesh.texture   = txtImg
            txtMesh.texCoords = { vec2(0,0), vec2(1,0), vec2(1,1),
                                  vec2(0,0), vec2(1,1), vec2(0,1) }    
            txtMesh:draw()
        end
    end
    
end

function touched(t)
    if t.state==MOVING then
        dy=dy+t.deltaY*vitesse
        --dx=dx+t.deltaX*vitesse
    end
end

@Techdojo i’ve succeeded in inserting Diablo76 function ( horizontal gradient ) but not your function ( vertical gradient ). It’s a pity. It’s very usefull for good presentation.

Without trying to run the code I can’t say - however it does look like you’re recreating the mesh every frame in the draw function - this isn’t really the best way to do this - also you appear to be reusing the same mesh over and over again - once per font.

What you should do is create the mesh once (even if it’s once at the top of the draw loop) and then just add each string to the mesh as a separate set of triangles (or even use the mesh:addRect() function.