Skip to content

Commit

Permalink
Add support for @letterspacing
Browse files Browse the repository at this point in the history
* Added on `syl` and `rend`
* The value is in MEI vu (default for data.MEASUREMENTSIGNED)
  • Loading branch information
lpugin committed Dec 11, 2023
1 parent 753f54b commit 92d8212
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/vrv/devicecontextbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class FontInfo {
FontInfo()
{
m_pointSize = 0;
m_letterSpacing = 0.0;
m_family = 0; // was wxFONTFAMILY_DEFAULT;
m_style = FONTSTYLE_NONE;
m_weight = FONTWEIGHT_NONE;
Expand All @@ -147,6 +148,7 @@ class FontInfo {

// accessors and modifiers for the font elements
int GetPointSize() const { return m_pointSize; }
int GetLetterSpacing() const { return m_letterSpacing; }
data_FONTSTYLE GetStyle() const { return m_style; }
data_FONTWEIGHT GetWeight() const { return m_weight; }
bool GetUnderlined() const { return m_underlined; }
Expand All @@ -158,6 +160,7 @@ class FontInfo {
SmuflTextFont GetSmuflFont() const { return m_smuflFont; }

void SetPointSize(int pointSize) { m_pointSize = pointSize; }
void SetLetterSpacing(double letterSpacing) { m_letterSpacing = letterSpacing; }
void SetStyle(data_FONTSTYLE style) { m_style = style; }
void SetWeight(data_FONTWEIGHT weight) { m_weight = weight; }
void SetUnderlined(bool underlined) { m_underlined = underlined; }
Expand All @@ -171,6 +174,7 @@ class FontInfo {

private:
int m_pointSize;
int m_letterSpacing;
int m_family;
data_FONTSTYLE m_style;
data_FONTWEIGHT m_weight;
Expand Down
2 changes: 0 additions & 2 deletions include/vrv/textelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class TextDrawingParams {
m_verticalShift = false;
m_alignment = HORIZONTALALIGNMENT_left;
m_pointSize = 0;
m_letterSpacing = 0;
m_actualWidth = 0;
m_enclose = TEXTRENDITION_NONE;
m_textEnclose = ENCLOSURE_NONE;
Expand All @@ -120,7 +119,6 @@ class TextDrawingParams {
bool m_verticalShift;
data_HORIZONTALALIGNMENT m_alignment;
int m_pointSize;
int m_letterSpacing;
std::vector<TextElement *> m_enclosedRend;
data_TEXTRENDITION m_enclose;
data_ENCLOSURE m_textEnclose;
Expand Down
6 changes: 6 additions & 0 deletions src/devicecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ void DeviceContext::AddGlyphToTextExtend(const Glyph *glyph, TextExtend *extend)
tmp = advX * m_fontStack.top()->GetPointSize();
advX = ceil(tmp / (double)glyph->GetUnitsPerEm());

const int letterSpacing = m_fontStack.top()->GetLetterSpacing();
// This is not the first letter, add a letter spacing
if ((letterSpacing != 0) && (extend->m_width > 0)) {
extend->m_width += letterSpacing;
}

// Changed because the width should only be the sum of advX
// Alternatively we could add what is below 0 for the first and what is beyond the advx for the last
// extend->m_width += std::max(partialWidth + x, advX);
Expand Down
4 changes: 4 additions & 0 deletions src/svgdevicecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@ void SvgDeviceContext::DrawText(
if (m_fontStack.top()->GetPointSize() != 0) {
textChild.append_attribute("font-size") = StringFormat("%dpx", m_fontStack.top()->GetPointSize()).c_str();
}
if (m_fontStack.top()->GetLetterSpacing() != 0.0) {
textChild.append_attribute("letter-spacing")
= StringFormat("%dpx", m_fontStack.top()->GetLetterSpacing()).c_str();
}
textChild.text().set(svgText.c_str());

if ((x != 0) && (y != 0) && (x != VRV_UNSET) && (y != VRV_UNSET) && (width != 0) && (height != 0)
Expand Down
3 changes: 3 additions & 0 deletions src/view_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,9 @@ void View::DrawSyl(DeviceContext *dc, LayerElement *element, Layer *layer, Staff
if (syl->GetStart() && syl->GetStart()->GetDrawingCueSize()) {
currentFont.SetPointSize(m_doc->GetCueSize(currentFont.GetPointSize()));
}
if (syl->HasLetterspacing()) {
currentFont.SetLetterSpacing(syl->GetLetterspacing() * m_doc->GetDrawingUnit(staff->m_drawingStaffSize));
}
dc->SetFont(&currentFont);

TextDrawingParams params;
Expand Down
5 changes: 5 additions & 0 deletions src/view_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void View::DrawDynamString(DeviceContext *dc, const std::u32string &str, TextDra
bool isFallbackNeeded = (m_doc->GetResources()).IsSmuflFallbackNeeded(smuflStr);
vrvTxt.SetSmuflWithFallback(isFallbackNeeded);
vrvTxt.SetStyle(FONTSTYLE_normal);
vrvTxt.SetLetterSpacing(90);
dc->SetFont(&vrvTxt);
this->DrawTextString(dc, smuflStr, params);
dc->ResetFont();
Expand Down Expand Up @@ -419,6 +420,10 @@ void View::DrawRend(DeviceContext *dc, Rend *rend, TextDrawingParams &params)
rendFont.SetWeight(rend->GetFontweight());
customFont = true;
}
if (rend->HasLetterspacing()) {
rendFont.SetLetterSpacing(rend->GetLetterspacing() * m_doc->GetDrawingUnit(100));
customFont = true;
}

if (customFont) dc->SetFont(&rendFont);

Expand Down

0 comments on commit 92d8212

Please sign in to comment.