Skip to content

Commit

Permalink
IO_Dxf: fix compilation error for OpenCascade < 7.5
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Dec 6, 2023
1 parent 7557715 commit c483e43
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/io_dxf/io_dxf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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<NCollection_String>(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);
}

Expand Down Expand Up @@ -523,7 +528,12 @@ void DxfReader::Internal::OnReadMText(const Dxf_MTEXT& text)

OccHandle<Font_TextFormatter> textFormat = new Font_TextFormatter;
textFormat->SetupAlignment(hAttachPnt, vAttachPnt);
#if OCC_VERSION_HEX >= OCC_VERSION_CHECK(7, 5, 0)
textFormat->Append(string_conv<NCollection_String>(text.str), *brepFont.FTFont());
#else
textFormat->Append(string_conv<NCollection_String>(text.str), brepFont);
#endif

#if 0
// Font_TextFormatter computes weird ResultWidth() so wrapping is currently broken
if (text.acadHasColumnInfo && text.acadColumnInfo_Width > 0.) {
Expand Down

0 comments on commit c483e43

Please sign in to comment.