sK1

[PATCH sk1libs] import/dxf: Use style's primaty font name in TEXT

Bug #600289 reported by Kirill Smelkov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
sK1
Confirmed
Undecided
Unassigned

Bug Description

In my DXF I have lots of TEXT entries which reference ST style as
attribute 7. And ST style itself looks like this:

          0
        STYLE
          5
        FF
        330
        3
        100
        AcDbSymbolTableRecord
        100
        AcDbTextStyleTableRecord
          2
        ST
         70
             0
         40
        0.0
         41
        1.0
         50
        15.0
         71
             0
         42
        3.0
          3
        geniso.shx
          4

So when load_text() tries to extract font_name from style['1000'] there
is nothing, and oops, I get lot's of crashes on TEXT nodes, e.g. like
this:

    DXFLoader: error
    Traceback (most recent call last):
      File "/home/kirr/src/tools/gfx/sk1/sk1/sk1libs/src/sk1libs/filters/import/dxfloader.py", line 1416, in run
        return_code = method()
      File "/home/kirr/src/tools/gfx/sk1/sk1/sk1libs/src/sk1libs/filters/import/dxfloader.py", line 1119, in load_text
        style_text.font = GetFont(font_name)
      File "/home/kirr/src/tools/gfx/sk1/sk1/sk1libs/src/sk1libs/ft2engine/__init__.py", line 148, in GetFont
        if fontname.count(family):
    AttributeError: 'NoneType' object has no attribute 'count'

According to DXF specification (I've checked R14 and 2011) "Primary font
file name" for a STYLE is attribute 3, so I think we should always try
to get font_name from there.

I don't know where attribute 1000 comes from (can't find a reference to it in
dxf spec), but if it is needed, let's leave a check for style['1000'] first so
that old behaviour is preserved, and we only use style['3'] when style['1000']
fails.

Doing so, resolves crashes and also makes text appear in destination SVG!
(tested with unioconvertor)

Please apply and thanks,
Kirill

Revision history for this message
Kirill Smelkov (kirr) wrote :
Revision history for this message
max (maxim-s-barabash) wrote :

This is not enough.
shx fonts are not supported anyway, the need to create an alias for ttf fonts.

For ttf font style['1000 '] contains information about the font family name.
In style['3'] contains the name of the font file.
To correct the error must be improved ft2engine.

Thanks.

max (maxim-s-barabash)
Changed in sk1:
status: New → Confirmed
Revision history for this message
Kirill Smelkov (kirr) wrote :

Max, thanks for your reply.

Am I right understanding you that we should put shx -> ttf font-name translation table into dxfloader.py? Or maybe even into ft2engine?

If such translation table is ok for dxfloader.py, I could try do it, but if it's deeper - sorry, I can't afford myself to dive in.

Thanks,
Kirill

P.S.

Just for the record: as already said, I have no style['1000'] entry in my DXF, and more, even when attribute 3 references geniso.shx, which is for sure absent on my system, in target SVG I get russian text more or less correctly rendered (as it turned out with fallback uniconvertor font BitstreamVeraSans-Roman).

That's why there is maybe a third option: just use shx font-name as-is, and issue an user-visible warning, that such-and-such dxf font was used without converting to TrueType.

Of course, it's a hack, but maybe if proper solution will be somehow delayed, it's better to have text with default font than not to have any text at all.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.