OCCT-Light 0.1
C ABI and C++ veneer for multi-language CAD workflows
Loading...
Searching...
No Matches
text.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 Capgemini Engineering Research and Development.
2//
3// This file is part of OCCT-Light software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Affero General Public License version 3 as published
7// by the Free Software Foundation, with an option to use any later version.
8// Consult the file LICENSE_AGPL_30.txt included in OCCT-Light distribution
9// for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of a commercial
12// license or contractual agreement.
13//
14// SPDX-License-Identifier: AGPL-3.0-or-later
15
24#ifndef OCCTL_HPP_TEXT_HPP
25#define OCCTL_HPP_TEXT_HPP
26
27#include <occtl/occtl_text.h>
28
29#include <occtl-hpp/core.hpp>
30#include <occtl-hpp/topo.hpp>
31
32#include <string>
33
34namespace occtl::text
35{
36
37namespace detail
38{
40inline ::occtl_axis2_placement_t default_ax2() noexcept
41{
42 return {{0.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {1.0, 0.0, 0.0}};
43}
44} // namespace detail
45
48{
49 ::occtl_axis2_placement_t placement = detail::default_ax2();
50 std::string font_family;
51 std::string font_path;
53 double height = 0.0;
56 double wrapping_width = 0.0;
57 bool word_wrapping = true;
58};
59
62
63namespace detail
64{
65inline ::occtl_text_info_t to_c_info(const std::string& theText,
66 const TextFacesOptions& theOpts,
68{
69 ::occtl_text_info_t anInfo = OCCTL_TEXT_INFO_INIT;
70 anInfo.placement = theOpts.placement;
71 anInfo.utf8_text = theText.c_str();
72 anInfo.font_family = theOpts.font_family.empty() ? nullptr : theOpts.font_family.c_str();
73 anInfo.font_path = theOpts.font_path.empty() ? nullptr : theOpts.font_path.c_str();
74 anInfo.font_aspect = theOpts.font_aspect;
75 anInfo.height = theOpts.height;
76 anInfo.horizontal_align = theOpts.horizontal_align;
77 anInfo.vertical_align = theOpts.vertical_align;
78 if (theOpts.wrapping_width > 0.0 || !theOpts.word_wrapping)
79 {
80 theLayout = OCCTL_TEXT_LAYOUT_OPTIONS_INIT;
81 theLayout.wrapping_width = theOpts.wrapping_width;
82 theLayout.word_wrapping = theOpts.word_wrapping ? 1 : 0;
83 anInfo.p_next = &theLayout;
84 }
85 return anInfo;
86}
87} // namespace detail
88
94inline TextMetrics measure(const std::string& theText, const TextFacesOptions& theOpts)
95{
96 ::occtl_text_layout_options_t aLayout = OCCTL_TEXT_LAYOUT_OPTIONS_INIT;
97 ::occtl_text_info_t anInfo = detail::to_c_info(theText, theOpts, aLayout);
98 ::occtl_text_metrics_t aMetrics = OCCTL_TEXT_METRICS_INIT;
99 check(::occtl_text_measure(&anInfo, &aMetrics));
100 return aMetrics;
101}
102
109inline NodeId make_faces(Graph& theGraph,
110 const std::string& theText,
111 const TextFacesOptions& theOpts)
112{
113 ::occtl_text_layout_options_t aLayout = OCCTL_TEXT_LAYOUT_OPTIONS_INIT;
114 ::occtl_text_info_t anInfo = detail::to_c_info(theText, theOpts, aLayout);
115
117 check(::occtl_text_make_faces(theGraph.get(), &anInfo, &anId));
118 return NodeId(anId);
119}
120
127inline NodeId make_wires(Graph& theGraph,
128 const std::string& theText,
129 const TextFacesOptions& theOpts)
130{
131 ::occtl_text_layout_options_t aLayout = OCCTL_TEXT_LAYOUT_OPTIONS_INIT;
132 ::occtl_text_info_t anInfo = detail::to_c_info(theText, theOpts, aLayout);
133
135 check(::occtl_text_make_wires(theGraph.get(), &anInfo, &anId));
136 return NodeId(anId);
137}
138
139} // namespace occtl::text
140
141#endif // OCCTL_HPP_TEXT_HPP
RAII handle for a topology graph. Mirrors occtl_graph_t.
Definition topo.hpp:1444
::occtl_graph_t * get() const noexcept
Borrows-it pointer to the underlying C handle, for direct ABI calls.
Definition topo.hpp:1494
Session-local identity of a graph node. Mirrors occtl_node_id_t.
Definition topo.hpp:52
C++ veneer for the core module.
void check(const ::occtl_status_t theStatus)
Throw on non-OK; otherwise a no-op.
Definition core.hpp:85
OCCT-Light: text-to-shape module public API.
struct occtl_text_metrics occtl_text_metrics_t
occtl_status_t occtl_text_make_wires(occtl_graph_t *graph, const occtl_text_info_t *info, occtl_node_id_t *out_compound)
enum occtl_text_font_aspect occtl_text_font_aspect_t
occtl_status_t occtl_text_make_faces(occtl_graph_t *graph, const occtl_text_info_t *info, occtl_node_id_t *out_compound)
@ OCCTL_TEXT_HALIGN_LEFT
Definition occtl_text.h:64
@ OCCTL_TEXT_VALIGN_BASELINE
Definition occtl_text.h:76
occtl_status_t occtl_text_measure(const occtl_text_info_t *info, occtl_text_metrics_t *out_metrics)
enum occtl_text_valign occtl_text_valign_t
enum occtl_text_halign occtl_text_halign_t
@ OCCTL_TEXT_FONT_ASPECT_REGULAR
Definition occtl_text.h:52
#define OCCTL_NODE_ID_INVALID
Definition occtl_topo_types.h:138
Optional layout/font knobs for make_faces and make_wires.
Definition text.hpp:48
double height
Glyph cap height in model units; strictly positive.
Definition text.hpp:53
bool word_wrapping
Avoid breaking words when wrapping.
Definition text.hpp:57
::occtl_axis2_placement_t placement
Baseline frame; defaults to XOY.
Definition text.hpp:49
std::string font_path
Absolute path to a .ttf/.otf file.
Definition text.hpp:51
double wrapping_width
Maximum line width; 0 disables wrapping.
Definition text.hpp:56
std::string font_family
Family name; ignored when font_path is set.
Definition text.hpp:50
Definition occtl_geom.h:128
Definition occtl_topo_types.h:50
Definition occtl_text.h:97
const void * p_next
Definition occtl_text.h:99
const char * font_path
Definition occtl_text.h:105
occtl_text_font_aspect_t font_aspect
Definition occtl_text.h:106
occtl_text_valign_t vertical_align
Definition occtl_text.h:109
occtl_text_halign_t horizontal_align
Definition occtl_text.h:108
double height
Definition occtl_text.h:107
occtl_axis2_placement_t placement
Definition occtl_text.h:100
const char * utf8_text
Definition occtl_text.h:101
const char * font_family
Definition occtl_text.h:103
Definition occtl_text.h:119
int32_t word_wrapping
Definition occtl_text.h:123
double wrapping_width
Definition occtl_text.h:122
Definition occtl_text.h:135
NodeId make_faces(Graph &theGraph, const std::string &theText, const TextFacesOptions &theOpts)
Builds a Compound of planar text faces and returns its NodeId. Throws occtl::Error on failure.
Definition text.hpp:109
NodeId make_wires(Graph &theGraph, const std::string &theText, const TextFacesOptions &theOpts)
Builds a Compound of glyph outline wires and returns its NodeId. Throws occtl::Error on failure.
Definition text.hpp:127
TextMetrics measure(const std::string &theText, const TextFacesOptions &theOpts)
Measures formatted text without creating graph topology. Throws occtl::Error on failure.
Definition text.hpp:94
C++ veneer for the topo module.