Fix axis defaults in OpenType 2 for PDF output (4518fd2c) · Commits · Inkscape / inkscape · GitLab
Martin Owens
·
2026-06-21
·
via Martin Owens activity
| Original line number |
Diff line number |
Diff line |
|
@@ -22,6 +22,7 @@ |
|
|
#include "remember-styles.h"
|
|
|
#include "style-enums.h"
|
|
|
|
|
|
class FontInstance;
|
|
|
class SPIPaint;
|
|
|
class SPAnchor;
|
|
|
class SPItem;
|
|
@@ -119,7 +120,7 @@ public: |
|
|
std::optional<CapyPDF_GraphicsStateId> get_group_graphics_state(SPStyle const *style,
|
|
|
std::optional<CapyPDF_TransparencyGroupId> sm);
|
|
|
std::optional<CapyPDF_GraphicsStateId> get_shape_graphics_state(SPStyle const *style);
|
|
|
std::optional<CapyPDF_FontId> get_font(std::string const &filename, SPIFontVariationSettings &var);
|
|
|
std::optional<std::pair<std::string, CapyPDF_FontId>> get_font(std::shared_ptr<FontInstance> font, SPIFontVariationSettings &var);
|
|
|
|
|
|
std::optional<capypdf::Color> get_paint(SPIPaint const &paint, SPStyle const *context_style,
|
|
|
std::optional<double> opacity);
|
|
|
| Original line number |
Diff line number |
Diff line |
|
@@ -16,6 +16,7 @@ |
|
|
#include "colors/spaces/cms.h"
|
|
|
#include "colors/spaces/cmyk.h"
|
|
|
#include "object/sp-gradient.h"
|
|
|
#include "libnrtype/font-instance.h"
|
|
|
#include "object/sp-paint-server.h"
|
|
|
#include "style.h"
|
|
|
|
|
@@ -287,18 +288,24 @@ std::optional<CapyPDF_GraphicsStateId> Document::get_shape_graphics_state(SPStyl |
|
|
*
|
|
|
* @returns the FontId in capypdf to use.
|
|
|
*/
|
|
|
std::optional<CapyPDF_FontId> Document::get_font(std::string const &filename, SPIFontVariationSettings &var)
|
|
|
std::optional<std::pair<std::string, CapyPDF_FontId>> Document::get_font(std::shared_ptr<FontInstance> font, SPIFontVariationSettings &var)
|
|
|
{
|
|
|
auto filename = font->GetFilename();
|
|
|
auto key = filename;
|
|
|
if (!var.axes.empty()) {
|
|
|
key += "-" + var.toString();
|
|
|
}
|
|
|
|
|
|
// TODO: It's possible for the font loading to fail but we don't know how yet.
|
|
|
if (!_font_cache.contains(key)) {
|
|
|
try {
|
|
|
auto fontprops = capypdf::FontProperties();
|
|
|
for (auto &[name, value] : var.axes) {
|
|
|
fontprops.set_variation(name, (int)value);
|
|
|
auto axes = font->get_opentype_varaxes();
|
|
|
for (auto &axis : axes) {
|
|
|
auto iter = var.axes.find(axis.tag);
|
|
|
fontprops.set_variation(axis.tag, iter == var.axes.end()
|
|
|
? (int)axis.def
|
|
|
: iter->second);
|
|
|
}
|
|
|
_font_cache[key] = _gen.load_font(filename.c_str(), fontprops);
|
|
|
} catch (std::exception const &err) {
|
|
@@ -306,7 +313,7 @@ std::optional<CapyPDF_FontId> Document::get_font(std::string const &filename, SP |
|
|
return {};
|
|
|
}
|
|
|
}
|
|
|
return _font_cache[key];
|
|
|
return {{key, _font_cache[key]}};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
| Original line number |
Diff line number |
Diff line |
|
@@ -19,6 +19,7 @@ |
|
|
#include "libnrtype/Layout-TNG.h"
|
|
|
#include "libnrtype/font-instance.h"
|
|
|
#include "style.h"
|
|
|
#include "style-text.h"
|
|
|
|
|
|
namespace Inkscape::Extension::Internal::PdfBuilder {
|
|
|
|
|
@@ -56,16 +57,16 @@ std::optional<double> TextContext::get_softmask(double opacity) const |
|
|
*/
|
|
|
bool TextContext::set_text_style(std::shared_ptr<FontInstance> const &font, SPStyle *style)
|
|
|
{
|
|
|
auto font_filename = font->GetFilename();
|
|
|
if (font_filename != last_font) {
|
|
|
if (auto font_id = _doc.get_font(font_filename, style->font_variation_settings)) {
|
|
|
if (auto ret = _doc.get_font(font, style->font_variation_settings)) {
|
|
|
auto &[key, font_id] = *ret;
|
|
|
if (key != last_font) {
|
|
|
// Transformation has consumed the font size
|
|
|
_tx.cmd_Tf(*font_id, 1); // style->font_size.computed);
|
|
|
last_font = font_filename;
|
|
|
_tx.cmd_Tf(font_id, 1); // style->font_size.computed);
|
|
|
last_font = key;
|
|
|
}
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
if (style->letter_spacing.set && style->letter_spacing.computed != last_letter_spacing) {
|
|
|
_tx.cmd_Tc(style->letter_spacing.computed / 1000);
|
|
|
last_letter_spacing = style->letter_spacing.computed;
|
|
|
| Original line number |
Diff line number |
Diff line |
|
@@ -39,7 +39,7 @@ private: |
|
|
bool _soft_mask;
|
|
|
|
|
|
// Text style memory
|
|
|
Glib::ustring last_font;
|
|
|
std::string last_font;
|
|
|
double last_letter_spacing = 0;
|
|
|
double last_ca = 1.0;
|
|
|
double last_CA = 1.0;
|
|
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。