Merge pull request #244 from KLayout/issue-241

Fixed issue-241 (no TextGenerator.default_generator for pymod)
This commit is contained in:
Matthias Köfferlein 2019-03-22 17:52:22 +01:00 committed by GitHub
commit 85808527c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 3710 additions and 32 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

@ -389,11 +389,6 @@ config.add_extension(_pya)
_db_path = os.path.join("src", "db", "db")
_db_sources = set(glob.glob(os.path.join(_db_path, "*.cc")))
# Not a real source:
# Caveat, in source distribution tarballs from pypi, these files will
# not exist. So we need an error-free discard method instead of list's remove.
_db_sources.discard(os.path.join(_db_path, "fonts.cc"))
_db = Library(config.root + '._db',
define_macros=config.macros() + [('MAKE_DB_LIBRARY', 1)],
include_dirs=[_tl_path, _gsi_path, _db_path],

View File

@ -36,6 +36,9 @@
#include <cctype>
// compiled with "scripts/compile_glyphs.rb":
#include "glyphs.cc_gen"
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

@ -67,7 +67,7 @@ struct HersheyFont
int width, height;
};
#include "fonts.cc"
#include "fonts.cc_gen"
const int line_spacing = 4;

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_gen Normal file

File diff suppressed because it is too large Load Diff