Fixed issue-241 (no TextGenerator.default_generator for pymod)

The issue was there because the fonts got imported
through Qt Resources. But in pymod there is no Qt.
The solution is to import them though compiled-in
blobs.
This commit is contained in:
Matthias Koefferlein 2019-03-21 23:11:52 +01:00
parent 57fb764f16
commit 69282f8fef
6 changed files with 3709 additions and 26 deletions

71
scripts/compile_glyphs.rb Executable file
View File

@ -0,0 +1,71 @@
#!/usr/bin/ruby
files = []
glyph_dir = File.join(File.dirname($0), "..", "src", "db", "db", "glyphs")
Dir::new(glyph_dir).each do |file|
if file !~ /^\./
files << file
end
end
ccfile = File.join(File.dirname($0), "..", "src", "db", "db", "glyphs.cc")
File.open(ccfile, "w") do |out|
out.puts <<"END"
/**
* THIS FILE HAS BEEN CREATED AUTOMATICALLY BY "compile_glyphs.rb"
* DO NOT EDIT!
*/
END
nfile = 0
files.each do |f|
nfile += 1
name = f.sub(/\..*$/, "")
out.puts("\n// File: #{f}")
out.puts("static const char *name_#{nfile} = \"#{name}\";")
out.puts("static const char *description_#{nfile} = \"#{f}\";")
out.puts("static const uint8_t data_#{nfile}[] = {");
File.open(File.join(glyph_dir, f), "rb") do |ly|
bytes = ly.read
hex = ""
bytes.size.times do |i|
hex += "0x%02x, " % bytes[i].ord
if i % 8 == 7
out.puts " " + hex
i = 0
hex = ""
end
end
if hex != ""
out.puts " " + hex
end
end
out.puts(" 0xff // dummy")
out.puts("};")
end
out.puts("\nstatic void load_glyphs (std::vector<db::TextGenerator> &generators)\n{\n")
nfile.times do |n|
out.puts(" generators.push_back (db::TextGenerator ());")
out.puts(" generators.back ().load_from_data ((const char *) data_#{n + 1}, sizeof (data_#{n + 1}) - 1, name_#{n + 1}, description_#{n + 1});\n")
end
out.puts("}")
end

View File

@ -36,6 +36,9 @@
#include <cctype>
// compiled with "scripts/compile_glyphs.rb":
#include "glyphs.cc"
namespace db
{
@ -155,13 +158,21 @@ TextGenerator::load_from_resource (const std::string &name)
QByteArray data = qUncompress (QByteArray ((const char *) res.data (), int (res.size ())));
load_from_data (data.constData (), data.size (), tl::to_string (QFileInfo (tl::to_qstring (name)).baseName ()), name);
}
#endif
void
TextGenerator::load_from_data (const char *data, size_t ndata, const std::string &name, const std::string &description)
{
db::Layout layout;
tl::InputMemoryStream memory_stream (data.constData (), data.size ());
tl::InputMemoryStream memory_stream (data, ndata);
tl::InputStream stream (memory_stream);
db::Reader reader (stream);
db::LayerMap map = reader.read (layout);
m_description = name;
m_description = description;
m_name = name;
std::pair<bool, unsigned int> l1 = map.logical (db::LDPair (1, 0));
std::pair<bool, unsigned int> l2 = map.logical (db::LDPair (2, 0));
@ -170,10 +181,7 @@ TextGenerator::load_from_resource (const std::string &name)
if (l1.first && l2.first) {
read_from_layout (layout, l1.second, l2.second, l3.second);
}
m_name = tl::to_string (QFileInfo (tl::to_qstring (name)).baseName ());
}
#endif
void
TextGenerator::load_from_file (const std::string &filename)
@ -323,22 +331,8 @@ TextGenerator::generators ()
s_fonts.clear ();
#if defined(HAVE_QT)
const char *resources[] = {
":/fonts/std_font.gds"
};
for (size_t i = 0 ; i < sizeof (resources) / sizeof (resources [0]); ++i) {
try {
tl::log << "Loading font from resource " << resources [i] << " ..";
s_fonts.push_back (TextGenerator ());
s_fonts.back ().load_from_resource (resources [i]);
} catch (tl::Exception &ex) {
tl::error << ex.msg ();
s_fonts.pop_back ();
}
}
#endif
// load the compiled-in glyphs
load_glyphs (s_fonts);
// scan for font files
for (std::vector<std::string>::const_iterator p = s_font_paths.begin (); p != s_font_paths.end (); ++p) {

View File

@ -83,6 +83,11 @@ public:
void load_from_resource (const std::string &name);
#endif
/**
* @brief Loads from the given binary data
*/
void load_from_data (const char *data, size_t ndata, const std::string &name, const std::string &description);
/**
* @brief Loads the font from the given file
*/

View File

@ -1,11 +1,8 @@
<RCC>
<qresource prefix="/fonts">
<file>std_font.gds</file>
</qresource>
<qresource prefix="/built-in-macros" >
<qresource prefix="/built-in-macros">
<file alias="pcell_declaration_helper.lym">built-in-macros/pcell_declaration_helper.lym</file>
</qresource>
<qresource prefix="/built-in-pymacros" >
<qresource prefix="/built-in-pymacros">
<file alias="pcell_declaration_helper.lym">built-in-pymacros/pcell_declaration_helper.lym</file>
</qresource>
</RCC>

3616
src/db/db/glyphs.cc Normal file

File diff suppressed because it is too large Load Diff