libredwg开源项目中的dwg2SVG命令可以将dwg文件转换成svg文件,实际使用发现转化后的svg相对于dwg存在mtext字段丢失问题,对代码进行分析发现代码中不处理DWG_TYPE_MTEXT字段,所以存在文字不显示的情况。
static int
output_object (Dwg_Object *obj)
{
int num = 1;
if (!obj)
{
fprintf (stderr, "object is NULL\n");
return 0;
}
switch (obj->fixedtype)
{
case DWG_TYPE_INSERT:
output_INSERT (obj);
break;
case DWG_TYPE_LINE:
output_LINE (obj);
break;
case DWG_TYPE_CIRCLE:
output_CIRCLE (obj);
break;
case DWG_TYPE_TEXT:
output_TEXT (obj);
break;
case DWG_TYPE_ARC:
output_ARC (obj);
break;
case DWG_TYPE_POINT:
output_POINT (obj);
break;
case DWG_TYPE_ELLIPSE:
output_ELLIPSE (obj);
break;
case DWG_TYPE_SOLID:
output_SOLID (obj);
break;
case DWG_TYPE__3DFACE:
output_3DFACE (obj);
break;
case DWG_TYPE_POLYLINE_2D:
output_POLYLINE_2D (obj);
break;
case DWG_TYPE_LWPOLYLINE:
output_LWPOLYLINE (obj);
break;
case DWG_TYPE_RAY:
output_RAY (obj);
break;
case DWG_TYPE_XLINE:
output_XLINE (obj);
break;
case DWG_TYPE_SEQEND:
case DWG_TYPE_VIEWPORT:
break;
default:
num = 0;
if (obj->supertype == DWG_SUPERTYPE_ENTITY)
fprintf (stderr, "%s ignored\n", obj->name);
// all other non-graphical objects are silently ignored
break;
}
return num;
}
// TODO: MTEXT
static void
output_TEXT (Dwg_Object *obj)
{
Dwg_Data *dwg = obj->parent;
Dwg_Entity_TEXT *text = obj->tio.entity->tio.TEXT;
char *escaped;
const char *fontfamily;
BITCODE_H style_ref = text->style;
Dwg_Object *o = style_ref ? dwg_ref_object_silent (dwg, style_ref) : NULL;
Dwg_Object_STYLE *style = o ? o->tio.object->tio.STYLE : NULL;
BITCODE_2DPOINT pt;
if (!text->text_value || entity_invisible (obj))
return;
if (isnan_2BD (text->ins_pt) || isnan_3BD (text->extrusion))
return;
if (dwg->header.version >= R_2007)
escaped = htmlwescape ((BITCODE_TU)text->text_value);
else
escaped = htmlescape (text->text_value, dwg->header.codepage);
if (style && o->fixedtype == DWG_TYPE_STYLE && style->font_file
&& *style->font_file
#ifdef HAVE_STRCASESTR
&& strcasestr (style->font_file, ".ttf")
#else
&& (strstr (style->font_file, ".ttf")
|| strstr (style->font_file, ".TTF"))
#endif
)
{
#ifdef HAVE_STRCASESTR
if (strcasestr (style->font_file, "Arial"))
#else
if ((strstr (style->font_file, "arial"))
|| strstr (style->font_file, "Arial"))
#endif
{
fontfamily = "Arial";
}
else
fontfamily = "Verdana";
}
else
fontfamily = "Courier";
transform_OCS_2d (&pt, text->ins_pt, text->extrusion);
printf ("\t<text id=\"dwg-object-%d\" x=\"%f\" y=\"%f\" "
"font-family=\"%s\" font-size=\"%f\" fill=\"%s\">%s</text>\n",
obj->index, transform_X (pt.x), transform_Y (pt.y), fontfamily,
text->height /* fontsize */, entity_color (obj->tio.entity),
escaped ? escaped : "");
free (escaped);
}