| 102 | //TODO: text is positioned slightly high (and left??) on page save to SVG file |
| 103 | |
| 104 | void 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("<"), "<"); |
| 160 | ss << lt; |
| 161 | } |
nothing calls this directly
no test coverage detected