MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / drawAnnotation

Method drawAnnotation

src/Mod/TechDraw/Gui/QGIViewAnnotation.cpp:104–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102//TODO: text is positioned slightly high (and left??) on page save to SVG file
103
104void QGIViewAnnotation::drawAnnotation()
105{
106 // Base::Console().message("QGIVA::drawAnnotation()\n");
107 auto viewAnno(dynamic_cast<TechDraw::DrawViewAnnotation*>(getViewObject()));
108 if (!viewAnno) {
109 return;
110 }
111
112 const std::vector<std::string>& annoRawText = viewAnno->Text.getValues();
113 std::vector<std::string> annoText;
114 // v0.19- stored text as escapedUnicode
115 // v0.20+ stores text as utf8
116 for (auto& line : annoRawText) {
117 if (line.find("\\x") == std::string::npos) {
118 // not escaped
119 annoText.push_back(line);
120 } else {
121 // is escaped
122 std::string newLine = Base::Tools::escapedUnicodeToUtf8(line);
123 annoText.push_back(newLine);
124 }
125 }
126
127 int scaledSize = exactFontSize(viewAnno->Font.getValue(), viewAnno->TextSize.getValue());
128
129 //build HTML/CSS formatting around Text lines
130 std::stringstream ss;
131 ss << "<html>\n<head>\n<style>\n";
132 ss << "p {";
133 ss << "font-family:" << viewAnno->Font.getValue() << "; ";
134 ss << "font-size:" << scaledSize << "px; ";
135 if (viewAnno->TextStyle.isValue("Normal")) {
136 ss << "font-weight:normal; font-style:normal; ";
137 } else if (viewAnno->TextStyle.isValue("Bold")) {
138 ss << "font-weight:bold; font-style:normal; ";
139 } else if (viewAnno->TextStyle.isValue("Italic")) {
140 ss << "font-weight:normal; font-style:italic; ";
141 } else if (viewAnno->TextStyle.isValue("Bold-Italic")) {
142 ss << "font-weight:bold; font-style:italic; ";
143 } else {
144 Base::Console().warning("%s has invalid TextStyle\n", viewAnno->getNameInDocument());
145 ss << "font-weight:normal; font-style:normal; ";
146 }
147 ss << "line-height:" << viewAnno->LineSpace.getValue() << "%; ";
148 Base::Color c = viewAnno->TextColor.getValue();
149 c = TechDraw::Preferences::getAccessibleColor(c);
150 ss << "color:" << c.asHexString() << "; ";
151 ss << "}\n</style>\n</head>\n<body>\n<p>";
152 for (std::vector<std::string>::const_iterator it = annoText.begin(); it != annoText.end();
153 it++) {
154 if (it != annoText.begin()) {
155 ss << "<br>";
156 }
157
158 //"less than" symbol chops off line. need to use html sub.
159 std::string lt = std::regex_replace((*it), std::regex("<"), "&lt;");
160 ss << lt;
161 }

Callers

nothing calls this directly

Calls 14

asHexStringMethod · 0.80
setHtmlMethod · 0.80
getValuesMethod · 0.45
findMethod · 0.45
push_backMethod · 0.45
getValueMethod · 0.45
isValueMethod · 0.45
warningMethod · 0.45
getNameInDocumentMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected