Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HACK: For speed, write out font styles only once. #124

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/DVIToSVGActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
** along with this program; if not, see <http://www.gnu.org/licenses/>. **
*************************************************************************/

#include <cassert>
#include <cstring>
#include <ctime>
#include "BoundingBox.hpp"
Expand Down Expand Up @@ -94,6 +95,8 @@ void DVIToSVGActions::setChar (double x, double y, unsigned c, bool vertical, co
// For a given font object, Font::uniqueFont() returns the same unique font object for
// all fonts with the same name.
_usedChars[SVGTree::USE_FONTS ? font.uniqueFont() : &font].insert(c);
assert(c >= 0 && c <= 127);
for (int cc = 0; cc <= 127; ++cc) _usedChars[SVGTree::USE_FONTS ? font.uniqueFont() : &font].insert(cc);

// However, we record all required fonts
_usedFonts.insert(&font);
Expand Down
3 changes: 3 additions & 0 deletions src/FontWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <algorithm>
#include <array>
#include <cassert>
#include "FontWriter.hpp"
#include "Message.hpp"
#include "utility.hpp"
Expand Down Expand Up @@ -156,7 +157,9 @@ static void writeSFD (const string &sfdname, const PhysicalFont &font, const set
"BeginChars: 1114112 " << charcodes.size() << '\n';

double extend = font.style() ? font.style()->extend : 1;
for (int c = 0; c <= 127; ++c) assert(charcodes.count(c) == 1);
for (int c : charcodes) {
assert(0 <= c && c <= 127);
string name = font.glyphName(c);
if (name.empty()) {
// if the font doesn't provide glyph names, use AGL name uFOO
Expand Down
29 changes: 22 additions & 7 deletions src/SVGTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@ void SVGTree::appendFontStyles (const unordered_set<const Font*> &fonts) {
for (const Font *font : fonts)
if (!dynamic_cast<const VirtualFont*>(font)) // skip virtual fonts
sortmap[FontManager::instance().fontID(font)] = font;
ostringstream style;
ostringstream styles;
static set<int> written_styles;
// add font style definitions in ascending order
for (auto &idfontpair : sortmap) {
if (CREATE_CSS) {
if (CREATE_CSS && written_styles.count(idfontpair.first) == 0) {
ostringstream style;
style << "text.f" << idfontpair.first << ' '
<< "{font-family:" << idfontpair.second->name()
<< ";font-size:" << XMLString(idfontpair.second->scaledSize()) << "px";
Expand All @@ -229,9 +231,14 @@ void SVGTree::appendFontStyles (const unordered_set<const Font*> &fonts) {
style << " /* " << info << " */";
}
style << '\n';
styles << style.str();
std::ofstream outfile;
outfile.open("font-styles.txt", std::ios_base::app);
outfile << style.str();
written_styles.insert(idfontpair.first);
}
}
styleCDataNode()->append(style.str());
// styleCDataNode()->append(styles.str());
}
}

Expand All @@ -244,12 +251,20 @@ void SVGTree::append (const PhysicalFont &font, const set<int> &chars, GFGlyphTr
if (chars.empty())
return;

static set<string> written_fonts;
if (USE_FONTS) {
if (FONT_FORMAT != FontWriter::FontFormat::SVG) {
ostringstream style;
FontWriter fontWriter(font);
if (fontWriter.writeCSSFontFace(FONT_FORMAT, chars, style, callback))
styleCDataNode()->append(style.str());
if (written_fonts.count(font.name()) == 0) {
ostringstream style;
FontWriter fontWriter(font);
if (fontWriter.writeCSSFontFace(FONT_FORMAT, chars, style, callback)) {
std::ofstream outfile;
outfile.open("font-faces.txt", std::ios_base::app);
outfile << style.str();
written_fonts.insert(font.name());
}
// styleCDataNode()->append(style.str());
}
}
else {
if (ADD_COMMENTS) {
Expand Down