Skip to content

Commit

Permalink
DXF: add font of TEXT and MTEXT to OGR style string (patch by Nikolai…
Browse files Browse the repository at this point in the history
… Lebedev, #198)

git-svn-id: https://svn.osgeo.org/gdal/trunk@37571 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
rouault committed Mar 3, 2017
1 parent ef47159 commit b771710
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions autotest/ogr/ogr_dxf.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def ogr_dxf_6():
gdaltest.post_reason( 'not keeping 2D text as 2D' )
return 'fail'

if feat.GetStyleString() != 'LABEL(f:"Arial",t:"Test",a:30,s:5g,p:7,c:#000000)':
if feat.GetStyleString() != 'LABEL(f:"normallatin1",t:"Test",a:30,s:5g,p:7,c:#000000)':
print(feat.GetStyleString())
gdaltest.post_reason( 'got wrong style string' )
return 'fail'
Expand Down Expand Up @@ -299,7 +299,7 @@ def ogr_dxf_9():
gdaltest.post_reason( 'Did not get expected first mtext.' )
return 'fail'

expected_style = 'LABEL(f:"Arial",t:"'+gdaltest.sample_style+'",a:45,s:0.5g,p:5,c:#000000)'
expected_style = 'LABEL(f:"normallatin1",t:"'+gdaltest.sample_style+'",a:45,s:0.5g,p:5,c:#000000)'
if feat.GetStyleString() != expected_style:
gdaltest.post_reason( 'Got unexpected style string:\n%s\ninstead of:\n%s.' % (feat.GetStyleString(),expected_style) )
return 'fail'
Expand Down Expand Up @@ -730,7 +730,7 @@ def ogr_dxf_16():
gdaltest.post_reason( 'Did not get expected first mtext.' )
return 'fail'

expected_style = 'LABEL(f:"Arial",t:"'+gdaltest.sample_style+'",a:45,s:0.5g,p:5,c:#000000)'
expected_style = 'LABEL(f:"normallatin1",t:"'+gdaltest.sample_style+'",a:45,s:0.5g,p:5,c:#000000)'
if feat.GetStyleString() != expected_style:
gdaltest.post_reason( 'Got unexpected style string:\n%s\ninstead of:\n%s.' % (feat.GetStyleString(),expected_style) )
return 'fail'
Expand Down
16 changes: 13 additions & 3 deletions gdal/ogr/ogrsf_frmts/dxf/ogrdxflayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ OGRFeature *OGRDXFLayer::TranslateMTEXT()
bool bHaveZ = false;
int nAttachmentPoint = -1;
CPLString osText;
CPLString osStyleName = "Arial";

while( (nCode = poDS->ReadValue(szLineBuf,sizeof(szLineBuf))) > 0 )
{
Expand Down Expand Up @@ -524,6 +525,10 @@ OGRFeature *OGRDXFLayer::TranslateMTEXT()
dfAngle = CPLAtof(szLineBuf);
break;

case 7:
osStyleName = TextUnescape(szLineBuf);
break;

default:
TranslateGenericProperty( poFeature, nCode, szLineBuf );
break;
Expand Down Expand Up @@ -596,7 +601,7 @@ OGRFeature *OGRDXFLayer::TranslateMTEXT()
CPLString osStyle;
char szBuffer[64];

osStyle.Printf("LABEL(f:\"Arial\",t:\"%s\"",osText.c_str());
osStyle.Printf("LABEL(f:\"%s\",t:\"%s\"", osStyleName.c_str(), osText.c_str());

if( dfAngle != 0.0 )
{
Expand Down Expand Up @@ -652,6 +657,7 @@ OGRFeature *OGRDXFLayer::TranslateTEXT()
double dfAngle = 0.0;
double dfHeight = 0.0;
CPLString osText;
CPLString osStyleName = "Arial";
bool bHaveZ = false;
int nAnchorPosition = 1;
int nHorizontalAlignment = 0;
Expand Down Expand Up @@ -695,6 +701,10 @@ OGRFeature *OGRDXFLayer::TranslateTEXT()
nVerticalAlignment = atoi(szLineBuf);
break;

case 7:
osStyleName = TextUnescape(szLineBuf);
break;

default:
TranslateGenericProperty( poFeature, nCode, szLineBuf );
break;
Expand Down Expand Up @@ -804,8 +814,8 @@ OGRFeature *OGRDXFLayer::TranslateTEXT()
CPLString osStyle;
char szBuffer[64];

osStyle.Printf("LABEL(f:\"Arial\",t:\"%s\"",osText.c_str());

osStyle.Printf("LABEL(f:\"%s\",t:\"%s\"", osStyleName.c_str(), osText.c_str());
osStyle += CPLString().Printf(",p:%d", nAnchorPosition);

if( dfAngle != 0.0 )
Expand Down

0 comments on commit b771710

Please sign in to comment.