8 #ifndef __VRV_SVG_DC_H__
9 #define __VRV_SVG_DC_H__
19 #include "devicecontext.h"
20 #include "fontstore.h"
54 void SetBackground(
int color,
int style = PEN_SOLID)
override;
55 void SetBackgroundImage(
void *image,
double opacity = 1.0)
override;
56 void SetBackgroundMode(
int mode)
override;
57 void SetTextForeground(
int color)
override;
58 void SetTextBackground(
int color)
override;
59 void SetLogicalOrigin(
int x,
int y)
override;
66 Point GetLogicalOrigin()
override;
79 void DrawQuadBezierPath(
Point bezier[3])
override;
80 void DrawCubicBezierPath(
Point bezier[4])
override;
81 void DrawCubicBezierPathFilled(
Point bezier1[4],
Point bezier2[4])
override;
82 void DrawBentParallelogramFilled(
Point side[4],
int height)
override;
83 void DrawCircle(
int x,
int y,
int radius)
override;
84 void DrawEllipse(
int x,
int y,
int width,
int height)
override;
85 void DrawEllipticArc(
int x,
int y,
int width,
int height,
double start,
double end)
override;
86 void DrawLine(
int x1,
int y1,
int x2,
int y2)
override;
87 void DrawPolyline(
int n,
Point points[],
bool close)
override;
88 void DrawPolygon(
int n,
Point points[])
override;
89 void DrawRectangle(
int x,
int y,
int width,
int height)
override;
90 void DrawRotatedText(
const std::string &text,
int x,
int y,
double angle)
override;
91 void DrawRoundedRectangle(
int x,
int y,
int width,
int height,
int radius)
override;
92 void DrawText(
const std::string &text,
const std::u32string &wtext = U
"",
int x = VRV_UNSET,
int y = VRV_UNSET,
93 int width = VRV_UNSET,
int height = VRV_UNSET)
override;
94 void DrawMusicText(
const std::u32string &text,
int x,
int y,
bool setSmuflGlyph =
false)
override;
95 void DrawSpline(
int n,
Point points[])
override;
96 void DrawGraphicUri(
int x,
int y,
int width,
int height,
const std::string &uri)
override;
97 void DrawSvgShape(
int x,
int y,
int width,
int height,
double scale, pugi::xml_node svg)
override;
98 void DrawBackgroundImage(
int x = 0,
int y = 0)
override;
105 void StartText(
int x,
int y, data_HORIZONTALALIGNMENT alignment = HORIZONTALALIGNMENT_left)
override;
106 void EndText()
override;
112 void MoveTextTo(
int x,
int y, data_HORIZONTALALIGNMENT alignment)
override;
113 void MoveTextVerticallyTo(
int y)
override;
125 void StartGraphic(
Object *
object,
const std::string &gClass,
const std::string &gId, GraphicID graphicID = PRIMARY,
126 bool prepend =
false)
override;
127 void EndGraphic(
Object *
object,
View *view)
override;
128 void AddGraphicClass(
const std::string &className)
override;
135 void StartCustomGraphic(
const std::string &name, std::string gClass =
"", std::string gId =
"")
override;
136 void EndCustomGraphic()
override;
153 void ResumeGraphic(
Object *
object, std::string gId)
override;
154 void EndResumedGraphic(
Object *
object,
View *view)
override;
161 void StartTextGraphic(
Object *
object,
const std::string &gClass,
const std::string &gId)
override;
162 void EndTextGraphic(
Object *
object,
View *view)
override;
169 void RotateGraphic(
Point const &orig,
double angle)
override;
176 void StartPage()
override;
177 void EndPage()
override;
184 void AddDescription(
const std::string &text)
override;
190 void AppendIdAndClass(
const std::string &gId,
const std::string &baseClass,
const std::string &addedClasses,
191 GraphicID graphicID = PRIMARY);
213 void SetFacsimile(
bool facsimile) { m_facsimile = facsimile; }
214 bool GetFacsimile() {
return m_facsimile; }
231 m_svgContentBoundingBoxes = svgContentBoundingBoxes;
265 this->PrefixCssRules(m_css);
274 for (std::string s : additionalAttributes) {
275 std::string className = s.substr(0, s.find(
"@"));
276 std::string attributeName = s.substr(s.find(
"@") + 1);
278 m_svgAdditionalAttributes.insert({ classId, attributeName });
285 void SetSmuflTextFont(option_SMUFLTEXTFONT smuflTextFont) { m_smuflTextFont = smuflTextFont; }
302 bool CopyFileToStream(
const std::string &filename, std::ostream &dest);
307 void DrawSvgBoundingBox(
Object *
object,
View *view);
313 void StartBoundingBoxGraphic(
Object *
object,
const std::string &gClass,
const std::string &gId);
318 void DrawSvgBoundingBoxRectangle(
int x,
int y,
int width,
int height);
323 void VrvTextFont() { m_vrvTextFont =
true; }
328 void VrvTextFontFallback() { m_vrvTextFontFallback =
true; }
333 void IncludeMusicTextFont(
const std::string &fontname);
338 void IncludeTextFontFaces(
const std::string &family,
const std::set<Resources::FaceStyle> &faceStyles);
343 void AppendFontFace(
const std::string &family,
const FontStore::FontFile &file, std::string src =
"");
349 void Commit(
bool xml_declaration);
351 void WriteLine(std::string);
353 std::string GetColor(
int color)
const;
355 pugi::xml_node AddChild(std::string name);
361 void AppendStrokeLineCap(pugi::xml_node node,
const Pen &pen);
362 void AppendStrokeLineJoin(pugi::xml_node node,
const Pen &pen);
363 void AppendStrokeDashArray(pugi::xml_node node,
const Pen &pen);
369 void PrefixCssRules(std::string &rules);
375 void DrawTextAsTspan(
const std::u32string &wtext,
int x,
int y,
int width,
int height);
376 void DrawTextAsPaths(
const std::u32string &wtext,
int x,
int y);
377 void FinishTextLine();
387 static bool IsInFontFamilyList(
const std::string &fontFamilyList,
const std::string &family);
402 bool m_vrvTextFontFallback;
408 std::ostringstream m_outdata;
411 int m_originX, m_originY;
415 std::map<std::string, std::set<Resources::FaceStyle>> m_textFontFaces;
417 double m_textCursorX;
419 double m_textLineWidth;
420 data_HORIZONTALALIGNMENT m_textAlignment;
421 pugi::xml_node m_textLineNode;
434 GlyphRef(
const Glyph *glyph,
int count,
const std::string &postfix);
435 const Glyph *GetGlyph()
const {
return m_glyph; };
436 const std::string &GetRefId()
const {
return m_refId; };
439 const Glyph *m_glyph;
442 const std::string InsertGlyphRef(
const Glyph *glyph);
443 std::vector<std::pair<const Glyph *, GlyphRef>> m_smuflGlyphs;
444 std::map<std::string, int> m_glyphCodeFontCounter;
447 pugi::xml_document m_svgDoc;
448 pugi::xml_node m_svgNode;
449 pugi::xml_node m_pageNode;
450 pugi::xml_node m_currentNode;
451 std::list<pugi::xml_node> m_svgNodeStack;
460 bool m_svgBoundingBoxes;
462 bool m_svgContentBoundingBoxes;
464 std::set<pugi::xml_node> m_textBoundingBoxNodes;
472 std::multimap<ClassId, std::string> m_svgAdditionalAttributes;
480 std::string m_glyphPostfixId;
482 option_SMUFLTEXTFONT m_smuflTextFont;
484 bool m_textEmbedFont;
This class is an abstract device context.
Definition: devicecontext.h:57
static ObjectFactory & GetInstance()
A static method returning a static object in order to guarantee initialisation.
ClassId GetClassId(const std::string &name)
Get the ClassId from the MEI element string name by making a lookup in the register.
This class represents a basic object.
Definition: object.h:66
Simple class for representing points.
Definition: devicecontextbase.h:203
This class implements a drawing context for generating SVG files.
Definition: svgdevicecontext.h:40
void SetSvgContentBoundingBoxes(bool svgContentBoundingBoxes)
Setting m_svgContentBoundingBoxes flag (false by default)
Definition: svgdevicecontext.h:229
void SetSvgViewBox(bool svgViewBox)
Setting m_svgViewBox flag (false by default)
Definition: svgdevicecontext.h:237
void SetCss(const std::string &css)
Setter for an additional CSS.
Definition: svgdevicecontext.h:262
void SetSmuflTextFont(option_SMUFLTEXTFONT smuflTextFont)
Setter for a the smufl text font option.
Definition: svgdevicecontext.h:285
void SetIndent(int indent)
Setter for indent of the SVG (default is 3, -1 for tabs)
Definition: svgdevicecontext.h:247
void SetTextEmbedFont(bool textEmbedFont)
Setting the flag for embedding the text fonts used (false by default)
Definition: svgdevicecontext.h:290
void AppendAdditionalAttributes(Object *object)
Append additional attributes, as given in m_svgAdditionalAttributes.
std::string GetStringSVG(bool xml_declaration=false)
}
void SetMMOutput(bool mmOutput)
Setting mm output flag (false by default)
Definition: svgdevicecontext.h:211
void SetTextAsPaths(bool textAsPaths)
Setting the flag for rendering text as glyph paths instead of SVG text (false by default)
Definition: svgdevicecontext.h:295
bool UseGlobalTextStyling() override
Text styles cannot be left to CSS when text is rendered as paths, and are needed for embedding the fa...
Definition: svgdevicecontext.h:206
bool UseGlobalStyling() override
In SVG use global styling but not with mm output (for pdf generation)
Definition: svgdevicecontext.h:201
void SetAdditionalAttributes(const std::vector< std::string > &additionalAttributes)
Copies additional attributes of defined elements to the SVG, each string in the form "elementName@att...
Definition: svgdevicecontext.h:272
void AppendIdAndClass(const std::string &gId, const std::string &baseClass, const std::string &addedClasses, GraphicID graphicID=PRIMARY)
Add id, data-id and class attributes.
void SetFormatRaw(bool rawFormat)
Set the SVG to have 'raw' formatting, with no extraneous whitespace or newlines.
Definition: svgdevicecontext.h:252
void SetRemoveXlink(bool removeXlink)
Removes the xlink: prefex on href attributes, necessary for some newer browsers.
Definition: svgdevicecontext.h:257
bool ApplyOffset() override
Indicate if offset should be applied.
Definition: svgdevicecontext.h:119
void SetShowHidden(bool showHidden)
Setting show hidden flag (false by default)
Definition: svgdevicecontext.h:219
void SetCustomGraphicAttributes(const std::string &data, const std::string &value) override
Method for adding custom graphic data-* attributes.
void SetHtml5(bool html5)
Setting m_html5 flag (false by default)
Definition: svgdevicecontext.h:242
void SetSvgBoundingBoxes(bool svgBoundingBoxes)
Setting m_svgBoudingBoxes flag (false by default)
Definition: svgdevicecontext.h:224
void SetCustomGraphicColor(const std::string &color) override
Method for changing the color of a custom graphic.
This class is a drawing context and corresponds to the view of a MVC design pattern.
Definition: view.h:109