|
Post by alexfish on Nov 5, 2023 0:20:12 GMT 1
Hi All did quick test on libhershey fonts using default CANVAS Requires :: libhersheyfont-dev Hershey vector fonts library development files Test case PRAGMA INCLUDE <hersheyfont.h> PRAGMA LDFLAGS -lhersheyfont OPTION PARSE FALSE INCLUDE "hug.bac"
SUB RENDER() LOCAL render_text$ = "HELLO WORLD"
LOCAL fontname$ = "rowmans" LOCAL hershey_font *hf = hershey_font_load(fontname$) TYPE struct
IF ( NOT(hf) ) THEN perror(fontname$) END END IF
LOCAL x_render_pos = 0
LOCAL p TYPE const char * LOCAL ch,px1,px2,py1,py2
FOR t = 1 TO LEN(render_text$) ch = ASC(MID$(render_text$, t, 1)) LOCAL hershey_glyph *hg = hershey_font_glyph(hf, ch) TYPE struct IF ( hg->width == 0 ) THEN CONTINUE LOCAL hershey_path *hp TYPE struct LOCAL i for ( hp=hg->paths; hp; hp=hp->next ) { LOCAL ptr for ( i=0; i<hp->nverts; i++ ) { REM the bits INCR ptr }
for ( i=0; i<hp->nverts; i++ ) { REM the bits IF i < ptr -1 THEN px1 = hp->verts[i].x + x_render_pos py1 = 0- hp->verts[i].y px2 = hp->verts[i+1].x + x_render_pos py2 = 0-hp->verts[i+1].y
LINE("#FF0000",px1 , py1 +25 ,px2 ,py2 +25) END IF }
} INCR x_render_pos,20 NEXT
hershey_font_free(hf)
END SUB
win = WINDOW("Fonts",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) RENDER() DISPLAY BR Alex Attachments:
|
|
|
Post by alexfish on Nov 5, 2023 0:26:44 GMT 1
List of fonts to try
/usr/share/hershey-fonts/astrology.jhf /usr/share/hershey-fonts/cursive.jhf /usr/share/hershey-fonts/cyrilc_1.jhf /usr/share/hershey-fonts/cyrillic.jhf /usr/share/hershey-fonts/futural.jhf /usr/share/hershey-fonts/futuram.jhf /usr/share/hershey-fonts/gothgbt.jhf /usr/share/hershey-fonts/gothgrt.jhf /usr/share/hershey-fonts/gothiceng.jhf /usr/share/hershey-fonts/gothicger.jhf /usr/share/hershey-fonts/gothicita.jhf /usr/share/hershey-fonts/gothitt.jhf /usr/share/hershey-fonts/greek.jhf /usr/share/hershey-fonts/greekc.jhf /usr/share/hershey-fonts/greeks.jhf /usr/share/hershey-fonts/japanese.jhf /usr/share/hershey-fonts/markers.jhf /usr/share/hershey-fonts/mathlow.jhf /usr/share/hershey-fonts/mathupp.jhf /usr/share/hershey-fonts/meteorology.jhf /usr/share/hershey-fonts/music.jhf /usr/share/hershey-fonts/rowmand.jhf /usr/share/hershey-fonts/rowmans.jhf /usr/share/hershey-fonts/rowmant.jhf /usr/share/hershey-fonts/scriptc.jhf /usr/share/hershey-fonts/scripts.jhf /usr/share/hershey-fonts/symbolic.jhf /usr/share/hershey-fonts/timesg.jhf /usr/share/hershey-fonts/timesi.jhf /usr/share/hershey-fonts/timesib.jhf /usr/share/hershey-fonts/timesr.jhf /usr/share/hershey-fonts/timesrb.jhf
|
|
|
Post by alexfish on Nov 5, 2023 0:49:35 GMT 1
different font + try a bit of scaling PRAGMA INCLUDE <hersheyfont.h> PRAGMA LDFLAGS -lhersheyfont OPTION PARSE FALSE INCLUDE "hug.bac"
SUB RENDER() LOCAL render_text$ = "HELLO WORLD"
LOCAL fontname$ = "rowmant" LOCAL hershey_font *hf = hershey_font_load(fontname$) TYPE struct
IF ( NOT(hf) ) THEN perror(fontname$) END END IF
LOCAL x_render_pos = 0
LOCAL p TYPE const char * LOCAL ch,px1,px2,py1,py2
FOR t = 1 TO LEN(render_text$) ch = ASC(MID$(render_text$, t, 1)) LOCAL hershey_glyph *hg = hershey_font_glyph(hf, ch) TYPE struct IF ( hg->width == 0 ) THEN CONTINUE LOCAL hershey_path *hp TYPE struct LOCAL i for ( hp=hg->paths; hp; hp=hp->next ) { LOCAL ptr for ( i=0; i<hp->nverts; i++ ) { REM the bits INCR ptr }
for ( i=0; i<hp->nverts; i++ ) { REM the bits IF i < ptr -1 THEN px1 = hp->verts[i].x + x_render_pos py1 = 0- hp->verts[i].y px2 = hp->verts[i+1].x + x_render_pos py2 = 0-hp->verts[i+1].y
LINE("#FF0000",px1*2 , py1*2 +50 ,px2*2 ,py2*2 +50) END IF }
} INCR x_render_pos,25 NEXT
hershey_font_free(hf)
END SUB
win = WINDOW("Fonts",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) RENDER() DISPLAY BR Alex Attachments:
|
|
|
Post by alexfish on Nov 5, 2023 2:54:41 GMT 1
For better control now have this OUT2 PRAGMA INCLUDE <hersheyfont.h> PRAGMA LDFLAGS -lhersheyfont OPTION PARSE FALSE INCLUDE "hug.bac" CONST HUG_BOLD = 1 CONST HUG_NORMAL = 0
SUB OUT2(hugtext$,hug_font$,hug_pressure,hug_accent,hug_advance,COLOUR$,hug_xpos,hug_ypos)
LOCAL hershey_font *hf = hershey_font_load(hug_font$) TYPE struct
IF ( NOT(hf) ) THEN perror(hug_font$) END END IF
LOCAL x_render_pos = 0
LOCAL p TYPE const char * LOCAL ch,px1,px2,py1,py2
FOR t = 1 TO LEN(hugtext$) ch = ASC(MID$(hugtext$, t, 1)) LOCAL hershey_glyph *hg = hershey_font_glyph(hf, ch) TYPE struct IF ( hg->width == 0 ) THEN CONTINUE LOCAL hershey_path *hp TYPE struct LOCAL i for ( hp=hg->paths; hp; hp=hp->next ) { LOCAL ptr for ( i=0; i<hp->nverts; i++ ) { REM the bits INCR ptr }
for ( i=0; i<hp->nverts; i++ ) { REM the bits IF i < ptr -1 THEN px1 = hp->verts[i].x + x_render_pos py1 = 0- hp->verts[i].y px2 = hp->verts[i+1].x + x_render_pos py2 = 0-hp->verts[i+1].y
LINE(COLOUR$,px1 + hug_xpos , py1 +hug_accent + hug_ypos ,px2+hug_xpos ,py2 +hug_accent + hug_ypos ) IF hug_pressure=HUG_BOLD THEN LINE(COLOUR$,px1 + hug_xpos+1 , py1 +hug_accent + hug_ypos ,px2+hug_xpos+1 ,py2 +hug_accent + hug_ypos) ENDIF END IF }
} INCR x_render_pos,hug_advance NEXT
hershey_font_free(hf)
END SUB
win = WINDOW("Fonts",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) ' text, font, pressure,accent,advance,color,xpos,ypos OUT2("HELLO WORLD","gothitt",HUG_BOLD,25,25,"#FF00FF",50,100 )
DISPLAY so depending on type of font play with the 'accent'(distance in the y) and the 'advance'(spacing) bit by bit esp the 'accent' BR Alex for scaling = DIY as per example If need Italics use "music" ; Attachments:
|
|
|
Post by alexfish on Nov 5, 2023 4:37:57 GMT 1
Last in the bits Suppose depending on the font :: read the code 'trying to sort the advance' PRAGMA INCLUDE <hersheyfont.h> PRAGMA LDFLAGS -lhersheyfont OPTION PARSE FALSE INCLUDE "hug.bac" CONST HUG_BOLD = 1 CONST HUG_NORMAL = 0 SUB OUT2(hugtext$,hug_font$,hug_pressure,hug_accent,hug_advance,COLOUR$,hug_xpos,hug_ypos)
LOCAL hershey_font *hf = hershey_font_load(hug_font$) TYPE struct
IF ( NOT(hf) ) THEN perror(hug_font$) END END IF
LOCAL x_render_pos = 0
LOCAL p TYPE const char * LOCAL ch,px1,px2,py1,py2
FOR t = 1 TO LEN(hugtext$) ch = ASC(MID$(hugtext$, t, 1)) LOCAL hershey_glyph *hg = hershey_font_glyph(hf, ch) TYPE struct IF ( hg->width == 0 ) THEN CONTINUE LOCAL hershey_path *hp TYPE struct LOCAL i for ( hp=hg->paths; hp; hp=hp->next ) { LOCAL ptr for ( i=0; i<hp->nverts; i++ ) { REM the bits INCR ptr }
for ( i=0; i<hp->nverts; i++ ) { REM the bits IF i < ptr -1 THEN px1 = hp->verts[i].x + x_render_pos py1 = 0- hp->verts[i].y px2 = hp->verts[i+1].x + x_render_pos py2 = 0-hp->verts[i+1].y
LINE(COLOUR$,px1 + hug_xpos , py1 +hug_accent + hug_ypos ,px2+hug_xpos ,py2 +hug_accent + hug_ypos ) IF hug_pressure=HUG_BOLD THEN LINE(COLOUR$,px1 + hug_xpos+1 , py1 +hug_accent + hug_ypos ,px2+hug_xpos+1 ,py2 +hug_accent + hug_ypos) ENDIF END IF }
} PRINT ch IF (ch = 105) OR (ch = 73) OR (ch = 32) OR (ch = 116) OR (ch = 108) OR (ch = 106) OR (ch = 74) THEN INCR x_render_pos,(hug_advance/2)+5 ELSE INCR x_render_pos,hug_advance END IF NEXT
hershey_font_free(hf)
END SUB
win = WINDOW("Fonts",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) ' text, font, pressure,accent,advance,color,xpos,ypos OUT2("IS THIS JUST A JOB","timesrb",HUG_BOLD,25,24,"#FF00FF",0,0 ) OUT2("is this just a job","music",HUG_BOLD,25,24,"#FF00FF",0,30 ) OUT2("NO IT IS NOT it is DIY","timesib",HUG_BOLD,25,24,"#FF00FF",0,60 ) OUT2("is this just a job","mathupp",HUG_BOLD,60,24,"#FF00FF",0,90 ) DISPLAY Notice The accent in the mathupp font
BR Alex Attachments:
|
|
|
Post by alexfish on Nov 5, 2023 4:52:21 GMT 1
PS
Clear your Cookie Jar before visiting this Forum
|
|
|
Post by alexfish on Nov 5, 2023 6:22:24 GMT 1
MM! another post
Yes
to find the advance, a bit came to mind , sorting the advance in another thread (Baking fonts) and also the 0-y was in the same thread
have left the API advance as is , can add extra advance for the font spacing
PRAGMA INCLUDE <hersheyfont.h> PRAGMA LDFLAGS -lhersheyfont OPTION PARSE FALSE INCLUDE "hug.bac" CONST HUG_BOLD = 1 CONST HUG_NORMAL = 0 SUB OUT2(hugtext$,hug_font$,hug_pressure,hug_accent,hug_advance,COLOUR$,hug_xpos,hug_ypos)
LOCAL hershey_font *hf = hershey_font_load(hug_font$) TYPE struct
IF ( NOT(hf) ) THEN perror(hug_font$) END END IF
LOCAL x_render_pos = 0
LOCAL p TYPE const char * LOCAL ch,px1,px2,py1,py2,npx,advance
FOR t = 1 TO LEN(hugtext$) advance =0 ch = ASC(MID$(hugtext$, t, 1)) LOCAL hershey_glyph *hg = hershey_font_glyph(hf, ch) TYPE struct IF ( hg->width == 0 ) THEN CONTINUE LOCAL hershey_path *hp TYPE struct LOCAL i for ( hp=hg->paths; hp; hp=hp->next ) { LOCAL ptr for ( i=0; i<hp->nverts; i++ ) { REM the bits INCR ptr }
for ( i=0; i<hp->nverts; i++ ) { REM the bits IF i < ptr -1 THEN npx = hp->verts[i+1].x IF npx > advance THEN advance = npx END IF px1 = hp->verts[i].x + x_render_pos py1 = 0- hp->verts[i].y px2 = hp->verts[i+1].x + x_render_pos py2 = 0-hp->verts[i+1].y
LINE(COLOUR$,px1 + hug_xpos , py1 +hug_accent + hug_ypos ,px2+hug_xpos ,py2 +hug_accent + hug_ypos ) IF hug_pressure=HUG_BOLD THEN LINE(COLOUR$,px1 + hug_xpos+1 , py1 +hug_accent + hug_ypos ,px2+hug_xpos+1 ,py2 +hug_accent + hug_ypos) ENDIF END IF }
} 'PRINT ch IF ch = 32 THEN INCR x_render_pos,15 ELSE INCR x_render_pos,advance + hug_advance END IF NEXT
hershey_font_free(hf)
END SUB
win = WINDOW("Fonts",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) ' text, font, pressure,accent,advance,color,xpos,ypos OUT2("Hello World","timesrb",HUG_BOLD,25,0,"#FF00FF",0,0 ) OUT2("Hello World","timesrb",HUG_BOLD,25,5,"#FF00FF",0,30 ) DISPLAY
BR Alex
|
|
|
Post by alexfish on Nov 5, 2023 11:17:56 GMT 1
Yet another
here refined advance + added GETACCENT + can use user accent to suit esp have weird font likes of math*
PRAGMA INCLUDE <hersheyfont.h> PRAGMA LDFLAGS -lhersheyfont OPTION PARSE FALSE INCLUDE "hug.bac" HUGOPTIONS("NOSCALING") CONST HUG_BOLD = 1 CONST HUG_NORMAL = 0
FUNCTION GETACCENT(hugtext$,hug_font$) LOCAL hershey_font *hf = hershey_font_load(hug_font$) TYPE struct
IF ( NOT(hf) ) THEN perror(hug_font$) END END IF
LOCAL p TYPE const char * LOCAL ch,npy,accenty FOR t = 1 TO LEN(hugtext$) accenty = 0 ch = ASC(MID$(hugtext$, t, 1)) LOCAL hershey_glyph *hg = hershey_font_glyph(hf, ch) TYPE struct IF ( hg->width == 0 ) THEN CONTINUE LOCAL hershey_path *hp TYPE struct LOCAL i for ( hp=hg->paths; hp; hp=hp->next ) { LOCAL ptr for ( i=0; i<hp->nverts; i++ ) { INCR ptr }
for ( i=0; i<hp->nverts; i++ ) { IF i < ptr -1 THEN npy = hp->verts[i].y IF npy > accenty THEN accenty = npy END IF
END IF }
}
NEXT RETURN accenty+3 hershey_font_free(hf) END FUNCTION
SUB OUT2(hugtext$,hug_font$,hug_pressure,hug_accent,hug_advance,COLOUR$,hug_xpos,hug_ypos)
LOCAL hershey_font *hf = hershey_font_load(hug_font$) TYPE struct
IF ( NOT(hf) ) THEN perror(hug_font$) END END IF
LOCAL x_render_pos = 0
LOCAL p TYPE const char * LOCAL ch,px1,px2,py1,py2,npx,advance,accenty
accenty=GETACCENT("A",hug_font$)
FOR t = 1 TO LEN(hugtext$) advance =0 ch = ASC(MID$(hugtext$, t, 1)) LOCAL hershey_glyph *hg = hershey_font_glyph(hf, ch) TYPE struct IF ( hg->width == 0 ) THEN CONTINUE LOCAL hershey_path *hp TYPE struct LOCAL i for ( hp=hg->paths; hp; hp=hp->next ) { LOCAL ptr for ( i=0; i<hp->nverts; i++ ) { INCR ptr }
for ( i=0; i<hp->nverts; i++ ) { IF i < ptr -1 THEN npx = hp->verts[i+1].x IF npx > advance THEN advance = npx END IF px1 = hp->verts[i].x + x_render_pos py1 = 0- hp->verts[i].y px2 = hp->verts[i+1].x + x_render_pos py2 = 0-hp->verts[i+1].y
LINE(COLOUR$,px1 + hug_xpos , py1 + accenty+hug_accent + hug_ypos ,px2+hug_xpos ,py2 +accenty+hug_accent + hug_ypos ) IF hug_pressure=HUG_BOLD THEN LINE(COLOUR$,px1 + hug_xpos+1 , py1 +accenty+hug_accent + hug_ypos ,px2+hug_xpos+1 ,py2+ accenty +hug_accent + hug_ypos) ENDIF END IF }
} 'PRINT ch IF ch = 32 THEN INCR x_render_pos,15 ELSE INCR x_render_pos,advance + 3 + hug_advance END IF
NEXT
hershey_font_free(hf)
END SUB
win = WINDOW("Fonts",900,400) can = CANVAS(900,400) ATTACH(win,can,0,0) ' text, font, pressure,accent,advance,color,xpos,ypos OUT2("Hello World this is a Bright New Day","music",HUG_BOLD,0,0,"#FF00FF",0,0 ) OUT2("What is poison=","gothicger",HUG_BOLD,0,0,"#FF00FF",0,30 ) DISPLAY
/* /usr/share/hershey-fonts/astrology.jhf /usr/share/hershey-fonts/cursive.jhf /usr/share/hershey-fonts/cyrilc_1.jhf /usr/share/hershey-fonts/cyrillic.jhf /usr/share/hershey-fonts/futural.jhf /usr/share/hershey-fonts/futuram.jhf /usr/share/hershey-fonts/gothgbt.jhf /usr/share/hershey-fonts/gothgrt.jhf /usr/share/hershey-fonts/gothiceng.jhf /usr/share/hershey-fonts/gothicger.jhf /usr/share/hershey-fonts/gothicita.jhf /usr/share/hershey-fonts/gothitt.jhf /usr/share/hershey-fonts/greek.jhf /usr/share/hershey-fonts/greekc.jhf /usr/share/hershey-fonts/greeks.jhf /usr/share/hershey-fonts/japanese.jhf /usr/share/hershey-fonts/markers.jhf /usr/share/hershey-fonts/mathlow.jhf /usr/share/hershey-fonts/mathupp.jhf /usr/share/hershey-fonts/meteorology.jhf /usr/share/hershey-fonts/music.jhf /usr/share/hershey-fonts/rowmand.jhf /usr/share/hershey-fonts/rowmans.jhf /usr/share/hershey-fonts/rowmant.jhf /usr/share/hershey-fonts/scriptc.jhf /usr/share/hershey-fonts/scripts.jhf /usr/share/hershey-fonts/symbolic.jhf /usr/share/hershey-fonts/timesg.jhf /usr/share/hershey-fonts/timesi.jhf /usr/share/hershey-fonts/timesib.jhf /usr/share/hershey-fonts/timesr.jhf /usr/share/hershey-fonts/timesrb.jhf */
BR Alex
|
|
|
Post by alexfish on Nov 5, 2023 11:38:42 GMT 1
As a Note of respect
have renamed the OUT2 to HERSHEY
HERSHEY("Hello World this is a Bright New Day","gothicger",HUG_NORMAL,0,0,"#FF00FF",0,0 )
BR Alex
|
|
|
Post by alexfish on Nov 5, 2023 13:33:34 GMT 1
Here testing up and coming HUG353 saved the bits in hershey.bac with header IE PRAGMA INCLUDE <hersheyfont.h> PRAGMA LDFLAGS -lhersheyfont OPTION PARSE FALSE
CONST HUG_BOLD = 1 CONST HUG_NORMAL = 0 test code INCLUDE "hug353pi.bac" INCLUDE "hershey.bac" HUGOPTIONS("NOSCALING") HUGOPTIONS("CANVAS CAIRO")
win = WINDOW("Fonts",900,400) can = CANVAS(900,400) ATTACH(win,can,0,0) ' text, font, pressure,accent,advance,color,xpos,ypos HERSHEY("CANVAS CAIRO","rowmans",HUG_BOLD,0,0,"#FF00FF",200,0 ) HERSHEY("Hello World this is a Bright New Day","gothicger",HUG_NORMAL,0,0,"#FF00FF",0,60 ) HERSHEY("ABCDXJPK","script",HUG_BOLD,0,0,"#FF00FF",0,90 )
DISPLAY UPDATE looking at the PICKY the "CANVAS" text look to close at the VA but here that VA looks the same tried the advance =2 and all look OK on the 'KVK' so the the advance can help with certain strings HERSHEY("CANVAS CAIRO BLAKVK","rowmans",HUG_BOLD,0,2,"#FF00FF",200,0 ) same in 'scriptc' HERSHEY("CANVAS CAIRO BLAKVK","scriptc",HUG_BOLD,0,0,"#FF00FF",200,0 ) ALL = OK HERSHEY("CANVAS CAIRO BLAKVK","rowmant",HUG_BOLD,0,0,"#FF00FF",200,0 ) = good Picky Attachments:
|
|
|
Post by alexfish on Nov 5, 2023 16:14:47 GMT 1
HUG353 has scale for fonts using "CANVAS CAIRO" SEE picky using hug_normal , hug_bold + scale Attachments:
|
|
|
Post by alexfish on Nov 6, 2023 6:46:49 GMT 1
Final screenshots of the to be HUG3.5.3 set bg to black + Hershey font settings SQUARE("#000000",0,0,900,400,1) HERSHEY("BaCon is a free BASIC to C translator","scripts",1.5,HUG_NORMAL,0,-3,"#FF00FF",30,30 ) HERSHEY("_____________________________________","rowmant",1.5,HUG_NORMAL,0,-3,"#FF00FF",5,45 ) HERSHEY("BaCon is a free BASIC to C translator","rowmant",1.5,HUG_NORMAL,0,-3,"#FF00FF",5,80 ) Attachments:
|
|