deeplook / svglib

Read SVG files and convert them to other formats.
GNU Lesser General Public License v3.0
322 stars 79 forks source link

[Feature] Anable font registration from outside svglibs #249

Closed mosc9575 closed 4 years ago

mosc9575 commented 4 years ago

It would be a great help if there was the opportunity to register a font from outside of the svglib in the same way it is possible in the included reportlab module.

Right now a font has to be in the folder ~/.fonts and the string for the font that should be registered has to be exact the same like the file with the .tff extension.

At the moment, it is possible to check if a font will be found, with svg.find_font(font_name). Inside of this function the registerFont function is used from reportlab like this registerFont(TTFont(font_name, '%s.ttf' % font_name)).

The downside of thie is, that there is no chance to modify the name of the font to use on the on hand and the path of the folder on the other hand.

In the example below, the reportlab module shows the wanted behavior.

from reportlab.pdfbase.ttfonts import TTFError, TTFont
from reportlab.pdfbase.pdfmetrics import registerFont
font_name = 'SourceSansPro'
path_string = '/home/fonts/SourceSansPro-Regular.ttf'
registerFont(TTFont(font_name, path_string))

The wish would be, that svglib gives the user the opportunity to register a font before futher actions.

deeplook commented 4 years ago

That sounds right. Do you feel like providing a patch?

mosc9575 commented 4 years ago

I never did before but I could try.

mosc9575 commented 4 years ago

The changes in #252 should add the wanted behavior.