28 std::string utf8_code;
29 static std::wstring_convert<std::codecvt_utf8<char32_t>,
char32_t> conv1;
31 for (
auto c : chars) {
32 utf8_code = conv1.to_bytes(
c);
42 , _soft_mask(soft_mask)
59 auto font_filename = font->GetFilename();
63 _tx.cmd_Tf(*font_id, 1);
86 _tx.set_nonstroke(*color);
91 _tx.set_stroke(*color);
108 if (values.size() > 1) {
115 if (soft_mask ||
last_ca < 1.0 || last_CA < 1.0 || style->fill_opacity < 1.0 || style->stroke_opacity < 1.0) {
116 auto gstate = capypdf::GraphicsState();
118 auto smask = capypdf::SoftMask(CAPY_SOFT_MASK_LUMINOSITY, *soft_mask);
153 double prev_advance = 0.0;
155 std::unique_ptr<capypdf::TextSequence> seq;
157 for (
auto &glyph : layout.
glyphs()) {
163 if (&glyph.span(&layout) == &span) {
164 auto Tm = glyph.transform(layout);
167 auto chars = glyph.characters(&layout);
171 if (chars.size() == 1 && (chars[0] ==
'\n' || chars[0] ==
'\r')) {
185 int kerning = (tr[
Geom::X] - prev_advance) * -1000;
188 seq->append_kerning(kerning);
196 seq = std::make_unique<capypdf::TextSequence>();
197 _tx.cmd_Tm(Tm[0], Tm[1], Tm[2], Tm[3], Tm[4], Tm[5]);
200 if (chars.size() == 1) {
202 seq->append_raw_glyph(glyph.glyph, chars[0]);
203 }
else if (chars.size() > 1) {
205 seq->append_ligature_glyph(glyph.glyph, text.c_str());
208 prev_advance = span.
font->Advance(glyph.glyph,
false);
229 tx.set_text_mode(CAPY_TEXT_CLIP);
232 for (Layout::Span
const &span : layout.
spans()) {
233 auto text_source =
static_cast<Layout::InputStreamTextSource
const *
>(input_stream[span.in_input_stream_item]);
234 if (text_source->Type() != Layout::InputStreamItemType::TEXT_SOURCE || span.line(&layout).hidden ||
238 if (!tx.set_text_style(span.font, text_source->style)) {
239 std::cerr <<
"Can't clip to text, no font available\n";
242 tx.render_text(layout, span);
246 }
catch (std::exception
const &
err) {
247 std::cerr <<
"Can't output text block:" <<
err.what() <<
"\n";
271 for (Layout::Span
const &span : layout.
spans()) {
272 auto text_source =
static_cast<Layout::InputStreamTextSource
const *
>(input_stream[span.in_input_stream_item]);
274 if (text_source->Type() != Layout::InputStreamItemType::TEXT_SOURCE || span.line(&layout).hidden ||
281 auto style = text_source->style;
283 tx.set_paint_style(style_map, style, context_style);
285 if (!tx.set_text_style(span.font, style)) {
286 std::cerr <<
"Can't export text, no font available\n";
293 tx.set_text_mode(CAPY_TEXT_FILL_STROKE);
294 tx.render_text(layout, span);
297 tx.set_text_mode(CAPY_TEXT_FILL);
298 tx.render_text(layout, span);
301 tx.set_text_mode(CAPY_TEXT_STROKE);
302 tx.render_text(layout, span);
312 }
catch (std::exception
const &
err) {
313 std::cerr <<
"Can't output text block:" <<
err.what() <<
"\n";
3x3 matrix representing an affine transformation.
Point translation() const
Gets the translation imparted by the Affine.
Affine inverse() const
Compute the inverse matrix.
StyleMemory & paint_memory()
std::optional< CapyPDF_FontId > get_font(std::string const &filename)
Load a font and cache the results.
std::optional< capypdf::Color > get_paint(SPIPaint const &paint, SPStyle const *context_style, std::optional< double > opacity)
Generate a solid color, gradient or pattern based on the SPIPaint.
capypdf::Generator & generator()
std::optional< CapyPDF_TransparencyGroupId > style_to_transparency_mask(SPStyle const *style, SPStyle const *context_style)
Render gradient transparencies into a transparency mask.
void clip_text_layout(Text::Layout const &layout)
Use the text object as a clipping mask in the PDF.
capypdf::DrawContext _ctx
void paint_text_layout(Text::Layout const &layout, SPStyle const *context_style)
Paint the given layout into the PDF document Drawing content.
std::optional< double > get_softmask(double opacity) const
capypdf::DrawContext & _ctx
void set_text_mode(CapyPDF_Text_Mode mode)
bool set_text_style(std::shared_ptr< FontInstance > const &font, SPStyle *style)
Set the text/font style, these are comment between clipping and painting.
TextContext(Document &doc, capypdf::DrawContext &ctx, bool soft_mask)
CapyPDF_Text_Mode last_text_mode
double last_letter_spacing
void render_text(Text::Layout const &layout, Text::Layout::Span const &span)
Render the text span into the text context.
void set_paint_style(StyleMap const &map, SPStyle const *style, SPStyle const *context_style)
Set the painting style, this is not applicable to clipping.
StyleMap get_changes_and_remember(SPStyle const *style)
Modify the changes scope without managing the FILO stack.
Generates the layout for either wrapped or non-wrapped text and stores the result.
std::vector< Layout::Glyph > const & glyphs() const
Publically allow access to the Layout::show logic outside of the Layout engine.
std::vector< InputStreamItem * > const & input_stream() const
double getActualLength() const
Get actual length of layout, by summing span lengths.
std::vector< Layout::Span > const & spans() const
T< SPAttr::FILL, SPIPaint > fill
fill
T< SPAttr::STROKE_DASHARRAY, SPIDashArray > stroke_dasharray
stroke-dasharray
T< SPAttr::STROKE, SPIPaint > stroke
stroke
T< SPAttr::LETTER_SPACING, SPILengthOrNormal > letter_spacing
letter spacing (css2 16.4)
T< SPAttr::STROKE_WIDTH, SPILength > stroke_width
stroke-width
T< SPAttr::FILL_OPACITY, SPIScale24 > fill_opacity
fill-opacity
T< SPAttr::STROKE_LINEJOIN, SPIEnum< SPStrokeJoinType > > stroke_linejoin
stroke-linejoin
T< SPAttr::STROKE_OPACITY, SPIScale24 > stroke_opacity
stroke-opacity
T< SPAttr::STROKE_MITERLIMIT, SPIFloat > stroke_miterlimit
stroke-miterlimit
T< SPAttr::STROKE_LINECAP, SPIEnum< SPStrokeCapType > > stroke_linecap
stroke-linecap
T< SPAttr::STROKE_DASHOFFSET, SPILength > stroke_dashoffset
stroke-dashoffset
Inkscape::XML::Document * _doc
Reference to the clipboard's Inkscape::XML::Document.
std::unordered_map< std::string, std::unique_ptr< SPDocument > > map
The data describing a single loaded font.
constexpr Coord EPSILON
Default "acceptably small" value.
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
CapyPDF_Line_Join get_linejoin(SPStrokeJoinType mode)
static std::string unicodeToUtf8(std::vector< gunichar > const &chars)
CapyPDF_Line_Cap get_linecap(SPStrokeCapType mode)
std::vector< PaintLayer > get_paint_layers(SPStyle const *style, SPStyle const *context_style)
Get a PDF specific layer painting pattern for fill, stroke and markers.
static void err(const char *fmt,...)
std::map< SPAttr, std::string > StyleMap
std::shared_ptr< FontInstance > font
SPStyle - a style object for SPItem objects.