diff --git a/src/Mod/Draft/draftmake/make_text.py b/src/Mod/Draft/draftmake/make_text.py index 690950f252..4d1f6e4ba8 100644 --- a/src/Mod/Draft/draftmake/make_text.py +++ b/src/Mod/Draft/draftmake/make_text.py @@ -41,7 +41,7 @@ if App.GuiUp: from draftviewproviders.view_text import ViewProviderText -def make_text(string, placement=None, screen=False): +def make_text(string, placement=None, screen=False, height=None): """Create a Text object containing the given list of strings. The current color and text height and font specified in preferences @@ -66,6 +66,9 @@ def make_text(string, placement=None, screen=False): If it is `True`, the text will always face perpendicularly to the camera direction, that is, it will be flat on the screen. + height: float, optional + A height value for the text, in mm + Returns ------- App::FeaturePython @@ -122,15 +125,16 @@ def make_text(string, placement=None, screen=False): if App.GuiUp: ViewProviderText(new_obj.ViewObject) - h = utils.get_param("textheight", 2) + if not height: # zero or None + height = utils.get_param("textheight", 2) new_obj.ViewObject.DisplayMode = "World" if screen: _msg("screen: {}".format(screen)) new_obj.ViewObject.DisplayMode = "Screen" - h = h * 10 + height *= 10 - new_obj.ViewObject.FontSize = h + new_obj.ViewObject.FontSize = height new_obj.ViewObject.FontName = utils.get_param("textfont", "") new_obj.ViewObject.LineSpacing = 1 diff --git a/src/Mod/Import/App/dxf/ImpExpDxf.cpp b/src/Mod/Import/App/dxf/ImpExpDxf.cpp index 315a56b2a9..e621611ac0 100644 --- a/src/Mod/Import/App/dxf/ImpExpDxf.cpp +++ b/src/Mod/Import/App/dxf/ImpExpDxf.cpp @@ -316,17 +316,21 @@ void ImpExpDxfRead::OnReadEllipse(const double* c, } -void ImpExpDxfRead::OnReadText(const double* point, const double /*height*/, const char* text) +void ImpExpDxfRead::OnReadText(const double* point, + const double height, + const char* text, + const double rotation) { if (optionImportAnnotations) { - Base::Vector3d pt(point[0] * optionScaling, - point[1] * optionScaling, - point[2] * optionScaling); if (LayerName().substr(0, 6) != "BLOCKS") { - App::Annotation* pcFeature = - static_cast(document->addObject("App::Annotation", "Text")); - pcFeature->LabelText.setValue(Deformat(text)); - pcFeature->Position.setValue(pt); + Base::Interpreter().runString("import Draft"); + Base::Interpreter().runStringArg("p=FreeCAD.Vector(%f,%f,%f)", + point[0] * optionScaling, + point[1] * optionScaling, + point[2] * optionScaling); + Base::Interpreter().runString("a=FreeCAD.Vector(0,0,1)"); + Base::Interpreter().runStringArg("pl=FreeCAD.Placement(p,a,%f)", rotation); + Base::Interpreter().runStringArg("Draft.make_text(\"%s\",pl, height=%f)", text, height); } // else std::cout << "skipped text in block: " << LayerName() << std::endl; } diff --git a/src/Mod/Import/App/dxf/ImpExpDxf.h b/src/Mod/Import/App/dxf/ImpExpDxf.h index b0f60adbff..b6a38970d0 100644 --- a/src/Mod/Import/App/dxf/ImpExpDxf.h +++ b/src/Mod/Import/App/dxf/ImpExpDxf.h @@ -43,7 +43,10 @@ public: // CDxfRead's virtual functions void OnReadLine(const double* s, const double* e, bool hidden) override; void OnReadPoint(const double* s) override; - void OnReadText(const double* point, const double height, const char* text) override; + void OnReadText(const double* point, + const double height, + const char* text, + const double rotation) override; void OnReadArc(const double* s, const double* e, const double* c, bool dir, bool hidden) override; void OnReadCircle(const double* s, const double* c, bool dir, bool hidden) override; diff --git a/src/Mod/Import/App/dxf/dxf.cpp b/src/Mod/Import/App/dxf/dxf.cpp index f43d58f2de..f681916027 100644 --- a/src/Mod/Import/App/dxf/dxf.cpp +++ b/src/Mod/Import/App/dxf/dxf.cpp @@ -2653,6 +2653,7 @@ bool CDxfRead::ReadText() { double c[3]; // coordinate double height = 0.03082; + double rotation = 0.0; std::string textPrefix; memset(c, 0, sizeof(c)); @@ -2668,7 +2669,15 @@ bool CDxfRead::ReadText() ss.imbue(std::locale("C")); switch (n) { case 0: - return false; + ResolveColorIndex(); + { + const char* utfStr = (this->*stringToUTF8)(textPrefix.c_str()); + OnReadText(c, height * 25.4 / 72.0, utfStr, rotation); + if (utfStr == m_str) { + delete utfStr; + } + } + return true; case 8: // Layer name follows get_line(); strcpy(m_layer_name, m_str); @@ -2714,6 +2723,15 @@ bool CDxfRead::ReadText() return false; } break; + case 50: + // text rotation + get_line(); + ss.str(m_str); + ss >> rotation; + if (ss.fail()) { + return false; + } + break; case 3: // Additional text that goes before the type 1 text // Note that if breaking the text into type-3 records splits a UFT-8 encoding we do @@ -2724,23 +2742,9 @@ bool CDxfRead::ReadText() break; case 1: // final text - // Note that we treat this as the end of the TEXT or MTEXT entity but this may cause - // us to miss other properties. Officially the entity ends at the start of the next - // entity, the BLKEND record that ends the containing BLOCK, or the ENDSEC record - // that ends the ENTITIES section. These are all code 0 records. Changing this would - // require either some sort of peek/pushback ability or the understanding that - // ReadText() and all the other Read... methods return having already read a code 0. get_line(); textPrefix.append(m_str); - ResolveColorIndex(); - { - const char* utfStr = (this->*stringToUTF8)(textPrefix.c_str()); - OnReadText(c, height * 25.4 / 72.0, utfStr); - if (utfStr == m_str) { - delete utfStr; - } - } - return (true); + break; case 62: // color index diff --git a/src/Mod/Import/App/dxf/dxf.h b/src/Mod/Import/App/dxf/dxf.h index ce577a432c..c5eb7f5814 100644 --- a/src/Mod/Import/App/dxf/dxf.h +++ b/src/Mod/Import/App/dxf/dxf.h @@ -392,8 +392,10 @@ public: {} ImportExport virtual void OnReadPoint(const double* /*s*/) {} - ImportExport virtual void - OnReadText(const double* /*point*/, const double /*height*/, const char* /*text*/) + ImportExport virtual void OnReadText(const double* /*point*/, + const double /*height*/, + const char* /*text*/, + const double /*rotation*/) {} ImportExport virtual void OnReadArc(const double* /*s*/, const double* /*e*/,