Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DXF style attribute of TEXT and MTEXT to OGR style string #198

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 15 additions & 5 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 @@ -595,8 +600,8 @@ 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 Expand Up @@ -2534,4 +2544,4 @@ int OGRDXFLayer::TestCapability( const char * pszCap )

{
return EQUAL(pszCap, OLCStringsAsUTF8);
}
}