Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Sep 4, 2024
1 parent 602d949 commit 16c78d1
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 44 deletions.
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(lunasvg PUBLIC LUNASVG_BUILD_STATIC)
endif()

include(GNUInstallDirs)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/lunasvg.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lunasvg)

include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/lunasvgConfig.cmake.in"
Expand All @@ -78,6 +75,12 @@ write_basic_package_version_file(lunasvgConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)

include(GNUInstallDirs)
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/lunasvg.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lunasvg
)

install(TARGETS lunasvg
EXPORT lunasvgTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand All @@ -87,8 +90,8 @@ install(TARGETS lunasvg

install(EXPORT lunasvgTargets
FILE lunasvgTargets.cmake
NAMESPACE lunasvg::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lunasvg
NAMESPACE lunasvg::
)

install(FILES
Expand Down
2 changes: 1 addition & 1 deletion source/lunasvg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ float Document::height() const

Box Document::boundingBox() const
{
return m_rootElement->paintBoundingBox();
return m_rootElement->localTransform().mapRect(m_rootElement->paintBoundingBox());
}

void Document::updateLayout()
Expand Down
58 changes: 29 additions & 29 deletions source/svglayoutstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static float parseNumberOrPercentage(std::string_view input, bool allowPercentag
return !input.empty() ? defaultValue : std::clamp(value, 0.f, 1.f);
}

static Length parseLength(std::string_view input, LengthNegativeMode mode, const Length& defaultValue)
static Length parseLength(const std::string_view& input, LengthNegativeMode mode, const Length& defaultValue)
{
Length value;
if(!value.parse(input, mode))
Expand Down Expand Up @@ -143,7 +143,7 @@ static float parseFontSize(std::string_view input, const SVGLayoutState* state)
}

template<typename Enum, unsigned int N>
static Enum parseEnumValue(std::string_view input, const SVGEnumerationEntry<Enum>(&entries)[N], Enum defaultValue)
static Enum parseEnumValue(const std::string_view& input, const SVGEnumerationEntry<Enum>(&entries)[N], Enum defaultValue)
{
for(const auto& entry : entries) {
if(input == entry.second) {
Expand All @@ -154,7 +154,7 @@ static Enum parseEnumValue(std::string_view input, const SVGEnumerationEntry<Enu
return defaultValue;
}

static Display parseDisplay(std::string_view input)
static Display parseDisplay(const std::string_view& input)
{
static const SVGEnumerationEntry<Display> entries[] = {
{Display::Inline, "inline"},
Expand All @@ -164,7 +164,7 @@ static Display parseDisplay(std::string_view input)
return parseEnumValue(input, entries, Display::Inline);
}

static Visibility parseVisibility(std::string_view input)
static Visibility parseVisibility(const std::string_view& input)
{
static const SVGEnumerationEntry<Visibility> entries[] = {
{Visibility::Visible, "visible"},
Expand All @@ -175,7 +175,7 @@ static Visibility parseVisibility(std::string_view input)
return parseEnumValue(input, entries, Visibility::Visible);
}

static Overflow parseOverflow(std::string_view input)
static Overflow parseOverflow(const std::string_view& input)
{
static const SVGEnumerationEntry<Overflow> entries[] = {
{Overflow::Visible, "visible"},
Expand All @@ -185,27 +185,16 @@ static Overflow parseOverflow(std::string_view input)
return parseEnumValue(input, entries, Overflow::Visible);
}

static FontStyle parseFontStyle(std::string_view input)
{
static const SVGEnumerationEntry<FontStyle> entries[] = {
{FontStyle::Normal, "normal"},
{FontStyle::Italic, "italic"},
{FontStyle::Italic, "oblique"}
};

return parseEnumValue(input, entries, FontStyle::Normal);
}

static FontWeight parseFontWeight(std::string_view input)
static FontWeight parseFontWeight(const std::string_view& input)
{
static const SVGEnumerationEntry<FontWeight> entries[] = {
{FontWeight::Normal, "normal"},
{FontWeight::Bold, "bold"},
{FontWeight::Normal, "100"},
{FontWeight::Normal, "200"},
{FontWeight::Normal, "300"},
{FontWeight::Normal, "400"},
{FontWeight::Normal, "500"},
{FontWeight::Bold, "bold"},
{FontWeight::Bold, "600"},
{FontWeight::Bold, "700"},
{FontWeight::Bold, "800"},
Expand All @@ -215,7 +204,18 @@ static FontWeight parseFontWeight(std::string_view input)
return parseEnumValue(input, entries, FontWeight::Normal);
}

static Direction parseDirection(std::string_view input)
static FontStyle parseFontStyle(const std::string_view& input)
{
static const SVGEnumerationEntry<FontStyle> entries[] = {
{FontStyle::Normal, "normal"},
{FontStyle::Italic, "italic"},
{FontStyle::Italic, "oblique"}
};

return parseEnumValue(input, entries, FontStyle::Normal);
}

static Direction parseDirection(const std::string_view& input)
{
static const SVGEnumerationEntry<Direction> entries[] = {
{Direction::Ltr, "ltr"},
Expand All @@ -225,7 +225,7 @@ static Direction parseDirection(std::string_view input)
return parseEnumValue(input, entries, Direction::Ltr);
}

static TextAnchor parseTextAnchor(std::string_view input)
static TextAnchor parseTextAnchor(const std::string_view& input)
{
static const SVGEnumerationEntry<TextAnchor> entries[] = {
{TextAnchor::Start, "start"},
Expand All @@ -236,7 +236,7 @@ static TextAnchor parseTextAnchor(std::string_view input)
return parseEnumValue(input, entries, TextAnchor::Start);
}

static WhiteSpace parseWhiteSpace(std::string_view input)
static WhiteSpace parseWhiteSpace(const std::string_view& input)
{
static const SVGEnumerationEntry<WhiteSpace> entries[] = {
{WhiteSpace::Default, "default"},
Expand All @@ -251,7 +251,7 @@ static WhiteSpace parseWhiteSpace(std::string_view input)
return parseEnumValue(input, entries, WhiteSpace::Default);
}

static MaskType parseMaskType(std::string_view input)
static MaskType parseMaskType(const std::string_view& input)
{
static const SVGEnumerationEntry<MaskType> entries[] = {
{MaskType::Luminance, "luminance"},
Expand All @@ -261,7 +261,7 @@ static MaskType parseMaskType(std::string_view input)
return parseEnumValue(input, entries, MaskType::Luminance);
}

static FillRule parseFillRule(std::string_view input)
static FillRule parseFillRule(const std::string_view& input)
{
static const SVGEnumerationEntry<FillRule> entries[] = {
{FillRule::NonZero, "nonzero"},
Expand All @@ -271,7 +271,7 @@ static FillRule parseFillRule(std::string_view input)
return parseEnumValue(input, entries, FillRule::NonZero);
}

static LineCap parseLineCap(std::string_view input)
static LineCap parseLineCap(const std::string_view& input)
{
static const SVGEnumerationEntry<LineCap> entries[] = {
{LineCap::Butt, "butt"},
Expand All @@ -282,7 +282,7 @@ static LineCap parseLineCap(std::string_view input)
return parseEnumValue(input, entries, LineCap::Butt);
}

static LineJoin parseLineJoin(std::string_view input)
static LineJoin parseLineJoin(const std::string_view& input)
{
static const SVGEnumerationEntry<LineJoin> entries[] = {
{LineJoin::Miter, "miter"},
Expand Down Expand Up @@ -310,8 +310,8 @@ SVGLayoutState::SVGLayoutState(const SVGLayoutState& parent, const SVGElement* e
, m_stroke_linejoin(parent.stroke_linejoin())
, m_fill_rule(parent.fill_rule())
, m_clip_rule(parent.clip_rule())
, m_font_style(parent.font_style())
, m_font_weight(parent.font_weight())
, m_font_style(parent.font_style())
, m_text_anchor(parent.text_anchor())
, m_white_space(parent.white_space())
, m_direction(parent.direction())
Expand Down Expand Up @@ -379,12 +379,12 @@ SVGLayoutState::SVGLayoutState(const SVGLayoutState& parent, const SVGElement* e
case PropertyID::Clip_Rule:
m_clip_rule = parseFillRule(input);
break;
case PropertyID::Font_Style:
m_font_style = parseFontStyle(input);
break;
case PropertyID::Font_Weight:
m_font_weight = parseFontWeight(input);
break;
case PropertyID::Font_Style:
m_font_style = parseFontStyle(input);
break;
case PropertyID::Direction:
m_direction = parseDirection(input);
break;
Expand Down
4 changes: 2 additions & 2 deletions source/svglayoutstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class SVGLayoutState {
FillRule fill_rule() const { return m_fill_rule; }
FillRule clip_rule() const { return m_clip_rule; }

FontStyle font_style() const { return m_font_style; }
FontWeight font_weight() const { return m_font_weight; }
FontStyle font_style() const { return m_font_style; }

TextAnchor text_anchor() const { return m_text_anchor; }
WhiteSpace white_space() const { return m_white_space; }
Expand Down Expand Up @@ -84,8 +84,8 @@ class SVGLayoutState {
FillRule m_fill_rule = FillRule::NonZero;
FillRule m_clip_rule = FillRule::NonZero;

FontStyle m_font_style = FontStyle::Normal;
FontWeight m_font_weight = FontWeight::Normal;
FontStyle m_font_style = FontStyle::Normal;

TextAnchor m_text_anchor = TextAnchor::Start;
WhiteSpace m_white_space = WhiteSpace::Default;
Expand Down
8 changes: 4 additions & 4 deletions source/svgproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ float LengthContext::valueForLength(const Length& length, LengthDirection direct
return length.value() / 100.f;
}

if(length.units() == LengthUnits::Em)
return length.value() * m_element->font_size();
if(length.units() == LengthUnits::Ex)
return length.value() * m_element->font_size() / 2.f;
if(length.units() == LengthUnits::Em)
return length.value() * m_element->font_size();
return length.value();
}

Expand Down Expand Up @@ -343,7 +343,7 @@ bool SVGLengthList::parse(std::string_view input)
return false;
input.remove_prefix(count);
skipOptionalSpacesOrComma(input);
m_values.push_back(std::move(value));
m_values.push_back(value);
}

return true;
Expand Down Expand Up @@ -386,7 +386,7 @@ bool SVGNumberList::parse(std::string_view input)
float value = 0.f;
if(!parseNumber(input, value))
return false;
skipOptionalSpaces(input);
skipOptionalSpacesOrComma(input);
m_values.push_back(value);
}

Expand Down
8 changes: 5 additions & 3 deletions source/svgtextelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ SVGTextFragmentsBuilder::SVGTextFragmentsBuilder(std::u32string& text, SVGTextFr
m_fragments.clear();
}

void SVGTextFragmentsBuilder::build(const SVGTextElement* element)
void SVGTextFragmentsBuilder::build(const SVGTextElement* textElement)
{
handleElement(element);
handleElement(textElement);
for(const auto& position : m_textPositions) {
fillCharacterPositions(position);
}
Expand Down Expand Up @@ -190,7 +190,9 @@ void SVGTextFragmentsBuilder::handleText(const SVGTextNode* node)
lastCharacter = currentCharacter;
}

m_textPositions.emplace_back(node, startOffset, m_text.length());
if(startOffset < m_text.length()) {
m_textPositions.emplace_back(node, startOffset, m_text.length());
}
}

void SVGTextFragmentsBuilder::handleElement(const SVGTextPositioningElement* element)
Expand Down
2 changes: 1 addition & 1 deletion source/svgtextelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SVGTextFragmentsBuilder {
public:
SVGTextFragmentsBuilder(std::u32string& text, SVGTextFragmentList& fragments);

void build(const SVGTextElement* element);
void build(const SVGTextElement* textElement);

private:
void handleText(const SVGTextNode* node);
Expand Down

0 comments on commit 16c78d1

Please sign in to comment.