From c483e4399914d1c026f25d02d850cb8eb5691552 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Wed, 6 Dec 2023 10:06:28 +0100 Subject: [PATCH] IO_Dxf: fix compilation error for OpenCascade < 7.5 --- src/io_dxf/io_dxf.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/io_dxf/io_dxf.cpp b/src/io_dxf/io_dxf.cpp index 07942a28..c889ea59 100644 --- a/src/io_dxf/io_dxf.cpp +++ b/src/io_dxf/io_dxf.cpp @@ -60,6 +60,15 @@ bool startsWith(std::string_view str, std::string_view prefix) return str.substr(0, prefix.size()) == prefix; } +std::string toLowerCase_C(const std::string& str) +{ + std::string lstr = str; + for (char& c : lstr) + c = std::tolower(c, std::locale::classic()); + + return lstr; +} + const Enumeration& systemFontNames() { static Enumeration fontNames; @@ -432,14 +441,8 @@ void DxfReader::Internal::OnReadText(const Dxf_TEXT& text) const Dxf_STYLE* ptrStyle = this->findStyle(text.styleName); std::string fontName = ptrStyle ? ptrStyle->name : m_params.fontNameForTextObjects; - auto fnToLower = [](const std::string& str) { - std::string lstr = str; - for (char& c : lstr) - c = std::tolower(c, std::locale::classic()); - return lstr; - }; - - if (fnToLower(fontName) == "arial_narrow") + // "ARIAL_NARROW" -> "ARIAL NARROW" + if (toLowerCase_C(fontName) == "arial_narrow") fontName.replace(5, 1, " "); const double fontHeight = 1.4 * text.height * m_params.scaling; @@ -455,6 +458,8 @@ void DxfReader::Internal::OnReadText(const Dxf_TEXT& text) rotTrsf.SetRotation(gp_Ax1(pt, gp::DZ()), UnitSystem::radians(text.rotationAngle * Quantity_Degree)); #if 0 + // TEXT justification is subtle(eg baseline and fit modes) + // See doc https://ezdxf.readthedocs.io/en/stable/tutorials/text.html const Dxf_TEXT::HorizontalJustification hjust = text.horizontalJustification; Graphic3d_HorizontalTextAlignment hAlign = Graphic3d_HTA_LEFT; switch (hjust) { @@ -482,7 +487,7 @@ void DxfReader::Internal::OnReadText(const Dxf_TEXT& text) const gp_Ax3 locText(pt, gp::DZ(), gp::DX().Transformed(rotTrsf)); Font_BRepTextBuilder brepTextBuilder; const auto textStr = string_conv(text.str); - const TopoDS_Shape shapeText = brepTextBuilder.Perform(brepFont, textStr, locText/*, hAlign, vAlign*/); + const TopoDS_Shape shapeText = brepTextBuilder.Perform(brepFont, textStr, locText); this->addShape(shapeText); } @@ -523,7 +528,12 @@ void DxfReader::Internal::OnReadMText(const Dxf_MTEXT& text) OccHandle textFormat = new Font_TextFormatter; textFormat->SetupAlignment(hAttachPnt, vAttachPnt); +#if OCC_VERSION_HEX >= OCC_VERSION_CHECK(7, 5, 0) textFormat->Append(string_conv(text.str), *brepFont.FTFont()); +#else + textFormat->Append(string_conv(text.str), brepFont); +#endif + #if 0 // Font_TextFormatter computes weird ResultWidth() so wrapping is currently broken if (text.acadHasColumnInfo && text.acadColumnInfo_Width > 0.) {