OGRErr OGRDXFWriterLayer::WriteTEXT( OGRFeature *poFeature ) { WriteValue( 0, "MTEXT" ); WriteCore( poFeature ); WriteValue( 100, "AcDbEntity" ); WriteValue( 100, "AcDbMText" ); /* -------------------------------------------------------------------- */ /* Do we have styling information? */ /* -------------------------------------------------------------------- */ OGRStyleTool *poTool = nullptr; OGRStyleMgr oSM; if( poFeature->GetStyleString() != nullptr ) { oSM.InitFromFeature( poFeature ); if( oSM.GetPartCount() > 0 ) poTool = oSM.GetPart(0); } /* ==================================================================== */ /* Process the LABEL tool. */ /* ==================================================================== */ double dfDx = 0.0; double dfDy = 0.0; if( poTool && poTool->GetType() == OGRSTCLabel ) { OGRStyleLabel *poLabel = (OGRStyleLabel *) poTool; GBool bDefault; /* -------------------------------------------------------------------- */ /* Color */ /* -------------------------------------------------------------------- */ if( poLabel->ForeColor(bDefault) != nullptr && !bDefault ) WriteValue( 62, ColorStringToDXFColor( poLabel->ForeColor(bDefault) ) ); /* -------------------------------------------------------------------- */ /* Angle */ /* -------------------------------------------------------------------- */ const double dfAngle = poLabel->Angle(bDefault); if( !bDefault ) WriteValue( 50, dfAngle ); /* -------------------------------------------------------------------- */ /* Height - We need to fetch this in georeferenced units - I'm */ /* doubt the default translation mechanism will be much good. */ /* -------------------------------------------------------------------- */ poTool->SetUnit( OGRSTUGround ); const double dfHeight = poLabel->Size(bDefault); if( !bDefault ) WriteValue( 40, dfHeight ); /* -------------------------------------------------------------------- */ /* Anchor / Attachment Point */ /* -------------------------------------------------------------------- */ const int nAnchor = poLabel->Anchor(bDefault); if( !bDefault ) { const static int anAnchorMap[] = { -1, 7, 8, 9, 4, 5, 6, 1, 2, 3, 7, 8, 9 }; if( nAnchor > 0 && nAnchor < 13 ) WriteValue( 71, anAnchorMap[nAnchor] ); } /* -------------------------------------------------------------------- */ /* Offset */ /* -------------------------------------------------------------------- */ dfDx = poLabel->SpacingX(bDefault); dfDy = poLabel->SpacingY(bDefault); /* -------------------------------------------------------------------- */ /* Escape the text, and convert to ISO8859. */ /* -------------------------------------------------------------------- */ const char *pszText = poLabel->TextString( bDefault ); if( pszText != nullptr && !bDefault ) { CPLString osEscaped = TextEscape( pszText ); while( osEscaped.size() > 250 ) { WriteValue( 3, osEscaped.substr( 0, 250 ).c_str() ); osEscaped.erase( 0, 250 ); } WriteValue( 1, osEscaped ); } /* -------------------------------------------------------------------- */ /* Store the text style in the map. */ /* -------------------------------------------------------------------- */ std::map<CPLString, CPLString> oTextStyleDef = PrepareTextStyleDefinition( poLabel ); CPLString osStyleName; for( const auto& oPair: oNewTextStyles ) { if( oPair.second == oTextStyleDef ) { osStyleName = oPair.first; break; } } if( osStyleName == "" ) { do { osStyleName.Printf( "AutoTextStyle-%d", nNextAutoID++ ); } while( poDS->oHeaderDS.TextStyleExists( osStyleName ) ); oNewTextStyles[osStyleName] = oTextStyleDef; } WriteValue( 7, osStyleName ); } delete poTool; /* -------------------------------------------------------------------- */ /* Write the location. */ /* -------------------------------------------------------------------- */ OGRPoint *poPoint = poFeature->GetGeometryRef()->toPoint(); WriteValue( 10, poPoint->getX() + dfDx ); if( !WriteValue( 20, poPoint->getY() + dfDy ) ) return OGRERR_FAILURE; if( poPoint->getGeometryType() == wkbPoint25D ) { if( !WriteValue( 30, poPoint->getZ() ) ) return OGRERR_FAILURE; } return OGRERR_NONE; }