Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::TextConfigurationSerialization Struct Reference

Public Member Functions

 TextConfigurationSerialization ()=delete
 

Static Public Member Functions

static EmbossStyle::Type get_type (std::string_view type)
 
static std::string_view get_name (EmbossStyle::Type type)
 
static void to_xml (std::stringstream &stream, const TextConfiguration &tc)
 
static void create_fix_and_store (std::stringstream &stream, TextConfiguration tc, const ModelVolume &volume)
 
static std::optional< TextConfigurationread (const char **attributes, unsigned int num_attributes)
 

Static Public Attributes

static const boost::bimap< EmbossStyle::Type, std::string_view > type_to_name
 

Detailed Description

Constructor & Destructor Documentation

◆ TextConfigurationSerialization()

Slic3r::TextConfigurationSerialization::TextConfigurationSerialization ( )
delete

Member Function Documentation

◆ create_fix_and_store()

void Slic3r::TextConfigurationSerialization::create_fix_and_store ( std::stringstream &  stream,
TextConfiguration  tc,
const ModelVolume volume 
)
static
3556{
3557 const auto& vertices = volume.mesh().its.vertices;
3558 assert(!vertices.empty());
3559 if (vertices.empty()) {
3560 to_xml(stream, tc);
3561 return;
3562 }
3563
3564 // IMPROVE: check if volume was modified (translated, rotated OR scaled)
3565 // when no change do not calculate transformation only store original fix matrix
3566
3567 // Create transformation used after load actual stored volume
3568 const Transform3d &actual_trmat = volume.get_transformation().get_matrix();
3569 Vec3d min = actual_trmat * vertices.front().cast<double>();
3570 Vec3d max = min;
3571 for (const Vec3f &v : vertices) {
3572 Vec3d vd = actual_trmat * v.cast<double>();
3573 for (size_t i = 0; i < 3; ++i) {
3574 if (min[i] > vd[i]) min[i] = vd[i];
3575 if (max[i] < vd[i]) max[i] = vd[i];
3576 }
3577 }
3578 Vec3d center = (max + min) / 2;
3579 Transform3d post_trmat = Transform3d::Identity();
3580 post_trmat.translate(center);
3581
3582 Transform3d fix_trmat = actual_trmat.inverse() * post_trmat;
3583 if (!tc.fix_3mf_tr.has_value()) {
3584 tc.fix_3mf_tr = fix_trmat;
3585 } else if (!fix_trmat.isApprox(Transform3d::Identity(), 1e-5)) {
3586 tc.fix_3mf_tr = *tc.fix_3mf_tr * fix_trmat;
3587 }
3588 to_xml(stream, tc);
3589}
EIGEN_DEVICE_FUNC Transform inverse(TransformTraits traits=(TransformTraits) Mode) const
Definition Transform.h:1202
static EIGEN_DEVICE_FUNC const Transform Identity()
Returns an identity transformation.
Definition Transform.h:539
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() min(const half &a, const half &b)
Definition Half.h:507
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
Definition Half.h:516
Eigen::Transform< double, 3, Eigen::Affine, Eigen::DontAlign > Transform3d
Definition Point.hpp:81
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:49
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:52
IGL_INLINE void volume(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedT > &T, Eigen::PlainObjectBase< Derivedvol > &vol)
Definition volume.cpp:15
static void to_xml(std::stringstream &stream, const TextConfiguration &tc)
Definition 3mf.cpp:3503

References Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::cast(), Slic3r::TextConfiguration::fix_3mf_tr, Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::inverse(), Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::isApprox(), and Eigen::Transform< _Scalar, _Dim, _Mode, _Options >::translate().

+ Here is the call graph for this function:

◆ get_name()

static std::string_view Slic3r::TextConfigurationSerialization::get_name ( EmbossStyle::Type  type)
inlinestatic
1918 {
1919 const auto& to_name = TextConfigurationSerialization::type_to_name.left;
1920 auto type_name = to_name.find(type);
1921 assert(type_name != to_name.end());
1922 if (type_name == to_name.end()) return "unknown type";
1923 return type_name->second;
1924 }
static const boost::bimap< EmbossStyle::Type, std::string_view > type_to_name
Definition 3mf.cpp:1908

◆ get_type()

static EmbossStyle::Type Slic3r::TextConfigurationSerialization::get_type ( std::string_view  type)
inlinestatic
1910 {
1911 const auto& to_type = TextConfigurationSerialization::type_to_name.right;
1912 auto type_item = to_type.find(type);
1913 assert(type_item != to_type.end());
1914 if (type_item == to_type.end()) return EmbossStyle::Type::undefined;
1915 return type_item->second;
1916 }

◆ read()

std::optional< TextConfiguration > Slic3r::TextConfigurationSerialization::read ( const char **  attributes,
unsigned int  num_attributes 
)
static
3592{
3593 FontProp fp;
3594 int char_gap = get_attribute_value_int(attributes, num_attributes, CHAR_GAP_ATTR);
3595 if (char_gap != 0) fp.char_gap = char_gap;
3596 int line_gap = get_attribute_value_int(attributes, num_attributes, LINE_GAP_ATTR);
3597 if (line_gap != 0) fp.line_gap = line_gap;
3598 float boldness = get_attribute_value_float(attributes, num_attributes, BOLDNESS_ATTR);
3599 if (std::fabs(boldness) > std::numeric_limits<float>::epsilon())
3600 fp.boldness = boldness;
3601 float skew = get_attribute_value_float(attributes, num_attributes, SKEW_ATTR);
3602 if (std::fabs(skew) > std::numeric_limits<float>::epsilon())
3603 fp.skew = skew;
3604 float distance = get_attribute_value_float(attributes, num_attributes, DISTANCE_ATTR);
3605 if (std::fabs(distance) > std::numeric_limits<float>::epsilon())
3606 fp.distance = distance;
3607 int use_surface = get_attribute_value_int(attributes, num_attributes, USE_SURFACE_ATTR);
3608 if (use_surface == 1) fp.use_surface = true;
3609 float angle = get_attribute_value_float(attributes, num_attributes, ANGLE_ATTR);
3610 if (std::fabs(angle) > std::numeric_limits<float>::epsilon())
3611 fp.angle = angle;
3612 int collection_number = get_attribute_value_int(attributes, num_attributes, COLLECTION_NUMBER_ATTR);
3613 if (collection_number > 0) fp.collection_number = static_cast<unsigned int>(collection_number);
3614
3615 fp.size_in_mm = get_attribute_value_float(attributes, num_attributes, LINE_HEIGHT_ATTR);
3616 fp.emboss = get_attribute_value_float(attributes, num_attributes, DEPTH_ATTR);
3617
3618 std::string family = get_attribute_value_string(attributes, num_attributes, FONT_FAMILY_ATTR);
3619 if (!family.empty()) fp.family = family;
3620 std::string face_name = get_attribute_value_string(attributes, num_attributes, FONT_FACE_NAME_ATTR);
3621 if (!face_name.empty()) fp.face_name = face_name;
3622 std::string style = get_attribute_value_string(attributes, num_attributes, FONT_STYLE_ATTR);
3623 if (!style.empty()) fp.style = style;
3624 std::string weight = get_attribute_value_string(attributes, num_attributes, FONT_WEIGHT_ATTR);
3625 if (!weight.empty()) fp.weight = weight;
3626
3627 std::string style_name = get_attribute_value_string(attributes, num_attributes, STYLE_NAME_ATTR);
3628 std::string font_descriptor = get_attribute_value_string(attributes, num_attributes, FONT_DESCRIPTOR_ATTR);
3629 std::string type_str = get_attribute_value_string(attributes, num_attributes, FONT_DESCRIPTOR_TYPE_ATTR);
3631 EmbossStyle fi{ style_name, std::move(font_descriptor), type, std::move(fp) };
3632
3633 std::string text = get_attribute_value_string(attributes, num_attributes, TEXT_DATA_ATTR);
3634
3635 std::optional<Transform3d> fix_tr_mat;
3636 std::string fix_tr_mat_str = get_attribute_value_string(attributes, num_attributes, TRANSFORM_ATTR);
3637 if (!fix_tr_mat_str.empty()) {
3638 fix_tr_mat = get_transform_from_3mf_specs_string(fix_tr_mat_str);
3639 }
3640
3641 return TextConfiguration{std::move(fi), std::move(text), std::move(fix_tr_mat)};
3642}
static constexpr const char * DISTANCE_ATTR
Definition 3mf.cpp:164
static constexpr const char * STYLE_NAME_ATTR
Definition 3mf.cpp:152
int get_attribute_value_int(const char **attributes, unsigned int attributes_size, const char *attribute_key)
Definition 3mf.cpp:221
static constexpr const char * FONT_FACE_NAME_ATTR
Definition 3mf.cpp:169
static constexpr const char * CHAR_GAP_ATTR
Definition 3mf.cpp:157
Slic3r::Transform3d get_transform_from_3mf_specs_string(const std::string &mat_str)
Definition 3mf.cpp:235
static constexpr const char * COLLECTION_NUMBER_ATTR
Definition 3mf.cpp:166
static constexpr const char * FONT_DESCRIPTOR_TYPE_ATTR
Definition 3mf.cpp:154
static constexpr const char * FONT_STYLE_ATTR
Definition 3mf.cpp:170
static constexpr const char * ANGLE_ATTR
Definition 3mf.cpp:165
static constexpr const char * FONT_DESCRIPTOR_ATTR
Definition 3mf.cpp:153
static constexpr const char * DEPTH_ATTR
Definition 3mf.cpp:160
static constexpr const char * SKEW_ATTR
Definition 3mf.cpp:163
static constexpr const char * LINE_GAP_ATTR
Definition 3mf.cpp:158
static constexpr const char * LINE_HEIGHT_ATTR
Definition 3mf.cpp:159
static constexpr const char * TEXT_DATA_ATTR
Definition 3mf.cpp:150
std::string get_attribute_value_string(const char **attributes, unsigned int attributes_size, const char *attribute_key)
Definition 3mf.cpp:207
static constexpr const char * TRANSFORM_ATTR
Definition 3mf.cpp:113
static constexpr const char * FONT_WEIGHT_ATTR
Definition 3mf.cpp:171
static constexpr const char * USE_SURFACE_ATTR
Definition 3mf.cpp:161
static constexpr const char * BOLDNESS_ATTR
Definition 3mf.cpp:162
static constexpr const char * FONT_FAMILY_ATTR
Definition 3mf.cpp:168
float get_attribute_value_float(const char **attributes, unsigned int attributes_size, const char *attribute_key)
Definition 3mf.cpp:213
#define style
Definition WipeTowerDialog.cpp:68
double angle(const Eigen::MatrixBase< Derived > &v1, const Eigen::MatrixBase< Derived2 > &v2)
Definition Point.hpp:112
double distance(const P &p1, const P &p2)
Definition geometry_traits.hpp:329
Type
Definition TextConfiguration.hpp:174
static EmbossStyle::Type get_type(std::string_view type)
Definition 3mf.cpp:1910

References Slic3r::angle(), Slic3r::FontProp::angle, ANGLE_ATTR, Slic3r::FontProp::boldness, BOLDNESS_ATTR, Slic3r::FontProp::char_gap, CHAR_GAP_ATTR, Slic3r::FontProp::collection_number, COLLECTION_NUMBER_ATTR, DEPTH_ATTR, Slic3r::FontProp::distance, DISTANCE_ATTR, Slic3r::FontProp::emboss, Slic3r::FontProp::face_name, Slic3r::FontProp::family, FONT_DESCRIPTOR_ATTR, FONT_DESCRIPTOR_TYPE_ATTR, FONT_FACE_NAME_ATTR, FONT_FAMILY_ATTR, FONT_STYLE_ATTR, FONT_WEIGHT_ATTR, get_attribute_value_float(), get_attribute_value_int(), get_attribute_value_string(), get_transform_from_3mf_specs_string(), Slic3r::FontProp::line_gap, LINE_GAP_ATTR, LINE_HEIGHT_ATTR, Slic3r::FontProp::size_in_mm, Slic3r::FontProp::skew, SKEW_ATTR, Slic3r::FontProp::style, style, STYLE_NAME_ATTR, TEXT_DATA_ATTR, TRANSFORM_ATTR, Slic3r::FontProp::use_surface, USE_SURFACE_ATTR, and Slic3r::FontProp::weight.

+ Here is the call graph for this function:

◆ to_xml()

void Slic3r::TextConfigurationSerialization::to_xml ( std::stringstream &  stream,
const TextConfiguration tc 
)
static
3504{
3505 stream << " <" << TEXT_TAG << " ";
3506
3507 stream << TEXT_DATA_ATTR << "=\"" << xml_escape_double_quotes_attribute_value(tc.text) << "\" ";
3508 // font item
3509 const EmbossStyle &fi = tc.style;
3510 stream << STYLE_NAME_ATTR << "=\"" << xml_escape_double_quotes_attribute_value(fi.name) << "\" ";
3511 stream << FONT_DESCRIPTOR_ATTR << "=\"" << xml_escape_double_quotes_attribute_value(fi.path) << "\" ";
3512 stream << FONT_DESCRIPTOR_TYPE_ATTR << "=\"" << TextConfigurationSerialization::get_name(fi.type) << "\" ";
3513
3514 // font property
3515 const FontProp &fp = tc.style.prop;
3516 if (fp.char_gap.has_value())
3517 stream << CHAR_GAP_ATTR << "=\"" << *fp.char_gap << "\" ";
3518 if (fp.line_gap.has_value())
3519 stream << LINE_GAP_ATTR << "=\"" << *fp.line_gap << "\" ";
3520
3521 stream << LINE_HEIGHT_ATTR << "=\"" << fp.size_in_mm << "\" ";
3522 stream << DEPTH_ATTR << "=\"" << fp.emboss << "\" ";
3523 if (fp.use_surface)
3524 stream << USE_SURFACE_ATTR << "=\"" << 1 << "\" ";
3525 if (fp.boldness.has_value())
3526 stream << BOLDNESS_ATTR << "=\"" << *fp.boldness << "\" ";
3527 if (fp.skew.has_value())
3528 stream << SKEW_ATTR << "=\"" << *fp.skew << "\" ";
3529 if (fp.distance.has_value())
3530 stream << DISTANCE_ATTR << "=\"" << *fp.distance << "\" ";
3531 if (fp.angle.has_value())
3532 stream << ANGLE_ATTR << "=\"" << *fp.angle << "\" ";
3533 if (fp.collection_number.has_value())
3534 stream << COLLECTION_NUMBER_ATTR << "=\"" << *fp.collection_number << "\" ";
3535 // font descriptor
3536 if (fp.family.has_value())
3537 stream << FONT_FAMILY_ATTR << "=\"" << *fp.family << "\" ";
3538 if (fp.face_name.has_value())
3539 stream << FONT_FACE_NAME_ATTR << "=\"" << *fp.face_name << "\" ";
3540 if (fp.style.has_value())
3541 stream << FONT_STYLE_ATTR << "=\"" << *fp.style << "\" ";
3542 if (fp.weight.has_value())
3543 stream << FONT_WEIGHT_ATTR << "=\"" << *fp.weight << "\" ";
3544
3545 // FIX of baked transformation
3546 assert(tc.fix_3mf_tr.has_value());
3547 stream << TRANSFORM_ATTR << "=\"";
3548 _3MF_Exporter::add_transformation(stream, *tc.fix_3mf_tr);
3549 stream << "\" ";
3550
3551 stream << "/>\n"; // end TEXT_TAG
3552}
static constexpr const char * TEXT_TAG
Definition 3mf.cpp:149
static void add_transformation(std::stringstream &stream, const Transform3d &tr)
Definition 3mf.cpp:2926
std::string xml_escape_double_quotes_attribute_value(std::string text)
Definition utils.cpp:964
static std::string_view get_name(EmbossStyle::Type type)
Definition 3mf.cpp:1918

References Slic3r::FontProp::angle, ANGLE_ATTR, Slic3r::FontProp::boldness, BOLDNESS_ATTR, Slic3r::FontProp::char_gap, CHAR_GAP_ATTR, Slic3r::FontProp::collection_number, COLLECTION_NUMBER_ATTR, DEPTH_ATTR, Slic3r::FontProp::distance, DISTANCE_ATTR, Slic3r::FontProp::emboss, Slic3r::FontProp::face_name, Slic3r::FontProp::family, Slic3r::TextConfiguration::fix_3mf_tr, FONT_DESCRIPTOR_ATTR, FONT_DESCRIPTOR_TYPE_ATTR, FONT_FACE_NAME_ATTR, FONT_FAMILY_ATTR, FONT_STYLE_ATTR, FONT_WEIGHT_ATTR, Slic3r::FontProp::line_gap, LINE_GAP_ATTR, LINE_HEIGHT_ATTR, Slic3r::EmbossStyle::name, Slic3r::EmbossStyle::path, Slic3r::EmbossStyle::prop, Slic3r::FontProp::size_in_mm, Slic3r::FontProp::skew, SKEW_ATTR, Slic3r::FontProp::style, Slic3r::TextConfiguration::style, STYLE_NAME_ATTR, Slic3r::TextConfiguration::text, TEXT_DATA_ATTR, TEXT_TAG, TRANSFORM_ATTR, Slic3r::EmbossStyle::type, Slic3r::FontProp::use_surface, USE_SURFACE_ATTR, Slic3r::FontProp::weight, and Slic3r::xml_escape_double_quotes_attribute_value().

+ Here is the call graph for this function:

Member Data Documentation

◆ type_to_name

const TypeToName Slic3r::TextConfigurationSerialization::type_to_name
static
Initial value:
=
boost::assign::list_of<TypeToName::relation>
(EmbossStyle::Type::wx_win_font_descr, "wxFontDescriptor_Windows")
(EmbossStyle::Type::wx_lin_font_descr, "wxFontDescriptor_Linux")
(EmbossStyle::Type::wx_mac_font_descr, "wxFontDescriptor_MacOsX")

The documentation for this struct was generated from the following file: