Cyrillic text plotted as ??? when I plot dxf from eeschema

Bug #1107767 reported by Konstantin Baranovskiy
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
KiCad
Fix Released
Undecided
Jacobo Aragunde Pérez

Bug Description

Cyrillic text displayed as ??? when I plot dxf from eeschema. At this time pcbnew plott it fine.

System: Ubuntu 12.10

Application: Eeschema
Version: (2012-10-17 BZR 3773 GOST)-testing
Build: wxWidgets 2.8.12 (no debug,Unicode,compiler with C++ ABI 1002,GCC 4.7.2,wx containers,compatible with 2.6)
Platform: Linux 3.7.3-030703-generic i686, 32 bit, Little endian, wxGTK
Boost version: 1.49.0
Options: USE_PCBNEW_SEXPR_FILE_FORMAT=OFF
         USE_PCBNEW_NANOMETRES=ON
         USE_PCBNEW_SEXPR_FOOTPRINT_LIBS=OFF
         KICAD_GOST=ON
         USE_WX_GRAPHICS_CONTEXT=OFF
         USE_WX_OVERLAY=OFF
         USE_BOOST_POLYGON_LIBRARY
         KICAD_SCRIPTING=OFF

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :
Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

Would you mind uploading the .sch file from which you exported the attached .dxf? Thank you!

Revision history for this message
Lorenzo Marcantonio (l-marcantonio) wrote : Re: [Bug 1107767] Re: Cyrillic text plotted as ??? when I plot dxf from eeschema

On Tue, Feb 05, 2013 at 09:08:52AM -0000, Jacobo Aragunde Pérez wrote:
> Would you mind uploading the .sch file from which you exported the
> attached .dxf? Thank you!

I have a suspect (the suspect is.. me :D); most probably it's exporting
the DXF in entity mode and the ISO font doesn't contain the required
characters; alternatively the DXF text isn't encoded properly (I don't
remember if it wants UTF-8 or whatever).

Could you check if the text in the DXF is done with MTEXT entities or
with LINES/LWPOLYLINES?

You could try to change the font in the text styles (if you're using
AutoCAD) to see if the missing characters appear.

--
Lorenzo Marcantonio
Logos Srl

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

The fact that pcbnew draws fine, but eeschema not.

Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

It looks like Eeschema uses text while Pcbnew uses lines. To make things more difficult, there is duplicated code in both applications. I will study it more and hopefully propose a solution soon.

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

Ok, thanks!

Revision history for this message
Lorenzo Marcantonio (l-marcantonio) wrote :

On Thu, Feb 07, 2013 at 05:41:35PM -0000, Jacobo Aragunde Pérez wrote:
> It looks like Eeschema uses text while Pcbnew uses lines. To make things
> more difficult, there is duplicated code in both applications. I will
> study it more and hopefully propose a solution soon.

It is an option in the 'common' plot library, the DXF plot engine can
happily do whatever you ask it to (actually even PS/PDF can use text
entities). I don't know how the vector font interact since I'm using
a patched (i.e. another font :D) version of it. Feel free to ask me for
anything about the plotting code.

There is another issue for DXF containing non-ascii characters: only
from IIRC R15 (i.e. AutoCAD 2000) they can contain unicode stuff; the
previous alternatives were custom font-encoding (typical for cyrillic)
or bigfont (100% proprietary autodesk solution).

So another thing which would be interesting is the program which he's
using for loading it.

--
Lorenzo Marcantonio
Logos Srl

Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

Found this code at DXF_PLOTTER::Text:

            /* Here I do a bad thing: writing the output one byte at a time!
               but today I'm lazy and I have no idea on how to coerce a Unicode
               wxString to spit out latin1 encoded text ...

               Atleast stdio is *supposed* to do output buffering, so there is
               hope is not too slow */
            wchar_t ch = aText[i];
            if( ch > 255 )
            {
                // I can't encode this...
                putc( '?', outputFile );
            }

That's why '?' signs appear when plotting the dxf from Eeschema.

I'll try to output unicode chars in this part of the code. Modern software should be able to handle it.

Changed in kicad:
assignee: nobody → Jacobo Aragunde Pérez (jaragunde)
Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

I am ready to help test.

Revision history for this message
Lorenzo Marcantonio (l-marcantonio) wrote :

On Fri, Feb 08, 2013 at 12:12:10PM -0000, Jacobo Aragunde Pérez wrote:
> Found this code at DXF_PLOTTER::Text:
>
>
> /* Here I do a bad thing: writing the output one byte at a time!
> but today I'm lazy and I have no idea on how to coerce a Unicode
> wxString to spit out latin1 encoded text ...

I confessed straight away :P:P

Uhm probably because in that place you need latin-1, for compatibility
with older DXF importer... and in latin1 you simply can't encode
cyrillic (hint: DXF was not meant for modern software :D)

You could try to look in recent DXF specs but the risk is losing
compatibility :(((

--
Lorenzo Marcantonio
Logos Srl

Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

What about reusing the code from Pcbnew? It seems to print the text as graphical elements, but as long as that's not a problem for the users of the DXF file, it could be a good solution.

Revision history for this message
Lorenzo Marcantonio (l-marcantonio) wrote :

On Mon, Feb 11, 2013 at 08:51:29AM -0000, Jacobo Aragunde Pérez wrote:
> What about reusing the code from Pcbnew? It seems to print the text as
> graphical elements, but as long as that's not a problem for the users of
> the DXF file, it could be a good solution.

Actually it's the same code being used... the way text is plotted is
*intended* to be configured/customized (it only need a checkbox in the
UI... in pcbnew is exposed to the scripting layer, too)

Look for the SetTextMode member in the PLOTTER classes!

Most probably it's a one-line patch... there's a trade-off between
having text-entities (i.e. searchability and compact drawing) and font
fidelity.

--
Lorenzo Marcantonio
Logos Srl

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

It would be possible to print the only cyrillic (or not supported) text as graphical elements. Supported characters can be printed as text. I think in this case, all will be satisfied))

Revision history for this message
Lorenzo Marcantonio (l-marcantonio) wrote :

On Mon, Feb 11, 2013 at 09:17:07AM -0000, Барановский Константин wrote:
> It would be possible to print the only cyrillic (or not supported) text
> as graphical elements. Supported characters can be printed as text. I
> think in this case, all will be satisfied))

You could add decision logic to see if a string contains the extended
chars and switch to stroke mode; you would have 'mixed' appearance but
it would work.

--
Lorenzo Marcantonio
Logos Srl

Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

I've added a check to plot non-ASCII text as lines, but I got an strange result when mixing both types.

Could you please open the attached file and tell me if you can see the second line of text? Looking at the generated file it seems to be correctly generated, but the software I used (Qcad CE) doesn't render it.

Changed in kicad:
status: New → In Progress
Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

I opened the attachment in LibreCAD, screenshot attached to the message. Everything looks good. Cyrillic drawn of lines, numbers and Latin as text.

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

Or rather the entire first row in which there is Cyrillic drawing of lines (with figures), and the second string is a text.

Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

Great! It looks like something weird was happening with my software, I couldn't even open the .dxf files you had attached last week.

I'm attaching the patch I used to generate the correct file.

Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

El 13/02/13 11:35, Барановский Константин escribió:
> Or rather the entire first row in which there is Cyrillic drawing of
> lines (with figures), and the second string is a text.
>

This is how it actually works :) . The lines with no special characters
are plotted as text.

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

Now tried to plot a dxf (with patch), text on the sheet is OK but the text on the frame to still shown as ???. And the vertical alignment not of the center and on the bottom.

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

I think I found what was wrong.

common_plotDXF_functions.cpp:649:

            /* Here I do a bad thing: writing the output one byte at a time!
               but today I'm lazy and I have no idea on how to coerce a Unicode
               wxString to spit out latin1 encoded text ...

               Atleast stdio is *supposed* to do output buffering, so there is
               hope is not too slow */
            wchar_t ch = aText[i];
            if( ch > 255 )
            {
                // I can't encode this...
                putc( '?', outputFile );
            }

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

I propose a solution: if plotted frame with dxf plotter in common_plot_function.cpp all text labels draw as lines (PLOTTEXTMODE_STROKE), else as native text (PLOTTEXTMODE_NATIVE).
Just need a way to know what the plotter used.
What do you think?

Revision history for this message
Lorenzo Marcantonio (l-marcantonio) wrote :

On Wed, Feb 13, 2013 at 01:31:17PM -0000, Барановский Константин wrote:
> I propose a solution: if plotted frame with dxf plotter in common_plot_function.cpp all text labels draw as lines (PLOTTEXTMODE_STROKE), else as native text (PLOTTEXTMODE_NATIVE).
> Just need a way to know what the plotter used.
> What do you think?

I have a better idea: look in DXF_PLOTTER::Text; first thing scan
the string looking for non suitable characters; then the if becomes

if( textAsLines || need_to_plot_strange_stuff )

and you solved the problem at the root... *every* string plotted to DXF would be handled correctly (no need for special cases or type dispatching). Also no need to touch other files, probably...

--
Lorenzo Marcantonio
Logos Srl

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

Ok, I'm add

...
    bool unknown = false;
    for( unsigned i = 0; i < aText.length(); i++ )
    {
        wchar_t ch = aText[i];
        if( ch > 255 )
        {
            unknown = true;
            break;
        }
    }

    if( textAsLines || unknown )
...

to common_plotDXF_functions.cpp in beginning of DXF_PLOTTER::Text, but the native text is not aligned in the center (as it should), it is at the bottom.

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

All figured out the problem in the most LibreCAD. Online viewer displaying all right.

Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

El 13/02/13 15:08, Lorenzo Marcantonio escribió:
>
> I have a better idea: look in DXF_PLOTTER::Text; first thing scan
> the string looking for non suitable characters; then the if becomes
>
> if( textAsLines || need_to_plot_strange_stuff )
>
> and you solved the problem at the root...

Hi Lorenzo! My patch follows a very similar approach, but I do the check
at SCH_TEXT::Plot. I will modify it to work as you suggest, to fix the
general case :)

Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

I've modified the patch according to Lorenzo's suggestions, and checked with an online viewer that the generated file is ok: it outputs graphics for those lines containing non-ASCII characters and standard TEXT otherwise.

Revision history for this message
Konstantin Baranovskiy (baranovskiykonstantin) wrote :

I restored sch_text.cpp and apply a new patch to the common_plotDXF_functions.cpp. Everything works fine. I think the problem is solved. Thank you for your work.

Changed in kicad:
status: In Progress → Fix Committed
Revision history for this message
jean-pierre charras (jp-charras) wrote :

Jacobo,
in your patch, line:
+bool containsNonAsciiChars( const wxString string )
Do you mean
+bool containsNonAsciiChars( const wxString& string )

It is not usual to pass the wxString itself.

Changed in kicad:
status: Fix Committed → In Progress
Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

My bad, old Java programmer habits die hard :D

I'm attaching the fixed patch.

Revision history for this message
Jacobo Aragunde Pérez (jaragunde) wrote :

At revision 3956.

Changed in kicad:
status: In Progress → Fix Committed
Jon Neal (reportingsjr)
Changed in kicad:
status: Fix Committed → Fix Released
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.