nathanielfernandes / imagetext-py

A blazing fast text drawing library
https://pypi.org/project/imagetext-py/
MIT License
69 stars 4 forks source link

Need help for "Usage" #12

Open mic-user opened 5 months ago

mic-user commented 5 months ago

Hi. it is nice package. However, cannot get over the first line that font query.

  1. In case designate custom font file folder myself, how to load a font with it?

for example, FontDB.LoadFromDir("c:\\custom_vari_font_folder\\") font = FontDB.Query( what should I put the name here? file name? or what? )

  1. When setup single font as below, how to map a fallback font? since there is no automatic fallback font mapping. FontDB.LoadFromPath('test_font', "c:\\custom_vari_font_folder\\test.ttf") font : Font = FontDB.Query("test_font")

  2. The 'LoadFromPath' takes first parameter as a name. Is it support any space included name? Seems does not. How to use/assign space included name with it? FontDB.LoadFromPath('test font', "c:\\custom_vari_font_folder\\test.ttf") font : Font = FontDB.Query("test font") <<< ERROR

nathanielfernandes commented 2 weeks ago

Hi @mic-user, you can use the method FontDbB.LoadPathFromDir, to load a singular font with a name. You can then query for that font name.

mic-user commented 1 week ago

Hi @mic-user, you can use the method FontDbB.LoadPathFromDir, to load a singular font with a name. You can then query for that font name.

Hey, another questions

  1. Is there any method that assign the 'Fallback font'?
  2. Is that possible to assign multiple fall back font?
nathanielfernandes commented 1 week ago
  1. you can add fallbacks to a font by just listing their names after the font in the FontDB.Query method.

ex.

myfont = FontDB.Query("mycoolfont fallback1 fallback2")
  1. yes
mic-user commented 1 week ago
  1. you can add fallbacks to a font by just listing their names after the font in the FontDB.Query method.

ex.

myfont = FontDB.Query("mycoolfont fallback1 fallback2")
  1. yes

That seem working. but need more help that if I wanna use Microsoft Windows default font as fallback as below, how should I do?

FontDB.LoadSystemFonts() #<<-- load stystem fonts FontDB.LoadFromPath('FontA', "x:\Font\A.ttf") FontDB.LoadFromPath('FontB', "x:\Font\B.ttf") font : Font = FontDB.Query("FontA MS-Gothic FontB") #<<-- MS-Gothic part seems not working

text = "hello ✓✔" draw_text_wrapped(canvas=cv, # the canvas to draw on text=text, x=256, y=256, # the position of the text ax=0.5, ay=0.5, # the anchor of the text size=32, # the size of the text width=500, # the width of the text font=font, fill=black, align=TextAlign.Center, stroke=2.0, # the stroke width (optional) stroke_color=rainbow, draw_emojis=True) # the stroke color (optional)