mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-13 09:47:58 -06:00
FIX: the text gap is not correct. STUDIO-2518
Change-Id: I27dc8b62962ebe1aa2b4d54e50d68cf173eecd54
This commit is contained in:
parent
bf08a0b2e2
commit
8ebd6cfc9e
3 changed files with 35 additions and 14 deletions
|
@ -95,7 +95,7 @@ std::vector<std::string> init_occt_fonts()
|
||||||
return stdFontNames;
|
return stdFontNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool TextToBRep(const char* text, const char* font, const float theTextHeight, Font_FontAspect& theFontAspect, TopoDS_Shape& theShape)
|
static bool TextToBRep(const char* text, const char* font, const float theTextHeight, Font_FontAspect& theFontAspect, TopoDS_Shape& theShape, double& text_width)
|
||||||
{
|
{
|
||||||
Standard_Integer anArgIt = 1;
|
Standard_Integer anArgIt = 1;
|
||||||
Standard_CString aName = "text_shape";
|
Standard_CString aName = "text_shape";
|
||||||
|
@ -122,8 +122,24 @@ static bool TextToBRep(const char* text, const char* font, const float theTextHe
|
||||||
|
|
||||||
aPenAx3 = gp_Ax3(aPenLoc, aNormal, aDirection);
|
aPenAx3 = gp_Ax3(aPenLoc, aNormal, aDirection);
|
||||||
|
|
||||||
|
Handle(Font_TextFormatter) aFormatter = new Font_TextFormatter();
|
||||||
|
aFormatter->Reset();
|
||||||
|
aFormatter->SetupAlignment(aHJustification, aVJustification);
|
||||||
|
aFormatter->Append(aText, *aFont.FTFont());
|
||||||
|
aFormatter->Format();
|
||||||
|
|
||||||
|
// get the text width
|
||||||
|
text_width = 0;
|
||||||
|
NCollection_String coll_str = aText;
|
||||||
|
for (NCollection_Utf8Iter anIter = coll_str.Iterator(); *anIter != 0;) {
|
||||||
|
const Standard_Utf32Char aCharThis = *anIter;
|
||||||
|
const Standard_Utf32Char aCharNext = *++anIter;
|
||||||
|
double width = aFont.AdvanceX(aCharThis, aCharNext);
|
||||||
|
text_width += width;
|
||||||
|
}
|
||||||
|
|
||||||
Font_BRepTextBuilder aBuilder;
|
Font_BRepTextBuilder aBuilder;
|
||||||
theShape = aBuilder.Perform(aFont, aText, aPenAx3, aHJustification, aVJustification);
|
theShape = aBuilder.Perform(aFont, aFormatter, aPenAx3);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +237,7 @@ static void MakeMesh(TopoDS_Shape& theSolid, TriangleMesh& theMesh)
|
||||||
theMesh.from_stl(stl);
|
theMesh.from_stl(stl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_text_shape(const char*text, const char* font, const float text_height, const float thickness, bool is_bold, bool is_italic, TriangleMesh& text_mesh)
|
void load_text_shape(const char*text, const char* font, const float text_height, const float thickness, bool is_bold, bool is_italic, TextResult &text_result)
|
||||||
{
|
{
|
||||||
Handle(Font_FontMgr) aFontMgr = Font_FontMgr::GetInstance();
|
Handle(Font_FontMgr) aFontMgr = Font_FontMgr::GetInstance();
|
||||||
if (aFontMgr->GetAvailableFonts().IsEmpty())
|
if (aFontMgr->GetAvailableFonts().IsEmpty())
|
||||||
|
@ -238,14 +254,14 @@ void load_text_shape(const char*text, const char* font, const float text_height,
|
||||||
else
|
else
|
||||||
aFontAspect = Font_FontAspect_Regular;
|
aFontAspect = Font_FontAspect_Regular;
|
||||||
|
|
||||||
if (!TextToBRep(text, font, text_height, aFontAspect, aTextBase))
|
if (!TextToBRep(text, font, text_height, aFontAspect, aTextBase, text_result.text_width))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TopoDS_Shape aTextShape;
|
TopoDS_Shape aTextShape;
|
||||||
if (!Prism(aTextBase, thickness, aTextShape))
|
if (!Prism(aTextBase, thickness, aTextShape))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MakeMesh(aTextShape, text_mesh);
|
MakeMesh(aTextShape, text_result.text_mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace Slic3r
|
}; // namespace Slic3r
|
||||||
|
|
|
@ -4,8 +4,14 @@
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
class TriangleMesh;
|
class TriangleMesh;
|
||||||
|
|
||||||
|
struct TextResult
|
||||||
|
{
|
||||||
|
TriangleMesh text_mesh;
|
||||||
|
double text_width;
|
||||||
|
};
|
||||||
|
|
||||||
extern std::vector<std::string> init_occt_fonts();
|
extern std::vector<std::string> init_occt_fonts();
|
||||||
extern void load_text_shape(const char* text, const char* font, const float text_height, const float thickness, bool is_bold, bool is_italic, TriangleMesh& text_mesh);
|
extern void load_text_shape(const char *text, const char *font, const float text_height, const float thickness, bool is_bold, bool is_italic, TextResult &text_result);
|
||||||
|
|
||||||
std::map<std::string, std::string> get_occt_fonts_maps();
|
std::map<std::string, std::string> get_occt_fonts_maps();
|
||||||
|
|
||||||
|
|
|
@ -934,10 +934,9 @@ bool GLGizmoText::update_text_positions(const std::vector<std::string>& texts)
|
||||||
} else {
|
} else {
|
||||||
alpha = texts[i];
|
alpha = texts[i];
|
||||||
}
|
}
|
||||||
TriangleMesh mesh;
|
TextResult text_result;
|
||||||
load_text_shape(alpha.c_str(), m_font_name.c_str(), m_font_size, m_thickness + m_embeded_depth, m_bold, m_italic, mesh);
|
load_text_shape(alpha.c_str(), m_font_name.c_str(), m_font_size, m_thickness + m_embeded_depth, m_bold, m_italic, text_result);
|
||||||
auto center = mesh.bounding_box().center();
|
double half_x_length = text_result.text_width / 2;
|
||||||
double half_x_length = center.x();
|
|
||||||
text_lengths.emplace_back(half_x_length);
|
text_lengths.emplace_back(half_x_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1356,13 +1355,13 @@ bool GLGizmoText::update_text_positions(const std::vector<std::string>& texts)
|
||||||
|
|
||||||
TriangleMesh GLGizmoText::get_text_mesh(const char* text_str, const Vec3d &position, const Vec3d &normal, const Vec3d& text_up_dir)
|
TriangleMesh GLGizmoText::get_text_mesh(const char* text_str, const Vec3d &position, const Vec3d &normal, const Vec3d& text_up_dir)
|
||||||
{
|
{
|
||||||
TriangleMesh mesh;
|
TextResult text_result;
|
||||||
load_text_shape(text_str, m_font_name.c_str(), m_font_size, m_thickness + m_embeded_depth, m_bold, m_italic, mesh);
|
load_text_shape(text_str, m_font_name.c_str(), m_font_size, m_thickness + m_embeded_depth, m_bold, m_italic, text_result);
|
||||||
|
TriangleMesh mesh = text_result.text_mesh;
|
||||||
|
|
||||||
auto center = mesh.bounding_box().center();
|
auto center = mesh.bounding_box().center();
|
||||||
double mesh_offset = center.z();
|
double mesh_offset = center.z();
|
||||||
|
mesh.translate(-text_result.text_width / 2, -m_font_size / 4, -center.z());
|
||||||
mesh.translate(-center.x(), -m_font_size / 4, -center.z());
|
|
||||||
|
|
||||||
double phi;
|
double phi;
|
||||||
Vec3d rotation_axis;
|
Vec3d rotation_axis;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue