mirror of https://github.com/KLayout/klayout.git
Fixed the font issue for Retina displays: there should be fixed fonts for all resolutions down to 1/6 (Retina display, 2x oversampling)
This commit is contained in:
parent
b04d9f38b9
commit
59b1849c96
|
|
@ -0,0 +1,127 @@
|
|||
|
||||
/*
|
||||
|
||||
KLayout Layout Viewer
|
||||
Copyright (C) 2006-2018 Matthias Koefferlein
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QFont>
|
||||
#include <QtGui/QBitmap>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QFontDialog>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* @brief A small utility program to produce the fixed font definition file
|
||||
* Run this binary and redirect the output to "laybasic/fixedFont.h".
|
||||
*/
|
||||
int
|
||||
main (int argc, char *argv [])
|
||||
{
|
||||
QApplication app (argc, argv);
|
||||
|
||||
printf ("\n// generated by fontgen\n// DO NOT EDIT !\n\n");
|
||||
|
||||
printf ("\nnamespace lay {\n");
|
||||
|
||||
std::string table;
|
||||
|
||||
int sz[] = { 9, 11, 13, 0 };
|
||||
|
||||
int os = 1;
|
||||
|
||||
for (int r = 1; r <= 6; ++r) {
|
||||
|
||||
for (int s = 0; sz[s] > 0; ++s) {
|
||||
|
||||
char b[1024];
|
||||
sprintf (b, " FixedFont (ff%d_height, ff%d_line_height, ff%d_width, ff%d_first_char, sizeof (ff%d_data) / sizeof (uint32_t) / (ff%d_height * ff%d_stride), ff%d_data, ff%d_stride),\n", os, os, os, os, os, os, os, os, os);
|
||||
table += b;
|
||||
|
||||
QFont f (QString::fromAscii ("Liberation Mono"), r * sz[s]);
|
||||
f.setStyleStrategy(QFont::StyleStrategy ((f.styleStrategy() & ~QFont::PreferAntialias) | QFont::NoAntialias));
|
||||
|
||||
QFontMetrics fm (f);
|
||||
|
||||
int w = fm.width (QChar::fromAscii ('W'));
|
||||
|
||||
printf ("\n// Font: %s\n", f.toString ().toAscii ().constData ());
|
||||
printf ("const unsigned int ff%d_height = %d;\nconst unsigned int ff%d_line_height = %d;\nconst unsigned int ff%d_width = %d;\nconst unsigned int ff%d_stride = %d;\n",
|
||||
os, fm.height (), os, fm.lineSpacing (), os, w, os, (w + 31) / 32);
|
||||
|
||||
printf ("const unsigned char ff%d_first_char = ' ';\n\nuint32_t ff%d_data [] = {\n", os, os);
|
||||
|
||||
for (int c = ' '; c < 256; ++c) {
|
||||
|
||||
QImage img (w, fm.height (), QImage::Format_RGB32);
|
||||
img.fill (0xffffffff);
|
||||
QPainter p (&img);
|
||||
p.setPen (Qt::black);
|
||||
p.setRenderHints (QPainter::TextAntialiasing, false);
|
||||
p.setFont (f);
|
||||
|
||||
char t[2];
|
||||
t[0] = c;
|
||||
t[1] = 0;
|
||||
p.drawText (0, fm.ascent (), QString::fromLatin1 (t));
|
||||
|
||||
QImage b = img.convertToFormat (QImage::Format_MonoLSB);
|
||||
|
||||
printf (" // %d", c);
|
||||
int n = 0;
|
||||
for (int i = 0; i < fm.height (); ++i) {
|
||||
|
||||
int ww = w;
|
||||
unsigned int *sl = (unsigned int *) b.scanLine (i);
|
||||
|
||||
do {
|
||||
|
||||
if ((n % 16) == 0) {
|
||||
printf ("\n ");
|
||||
}
|
||||
++n;
|
||||
|
||||
printf ("0x%x,", ww < 32 ? *sl & ((1 << ww) - 1) : *sl);
|
||||
ww -= 32;
|
||||
++sl;
|
||||
|
||||
} while (ww > 0);
|
||||
|
||||
}
|
||||
printf ("\n");
|
||||
|
||||
}
|
||||
|
||||
printf ("};\n");
|
||||
|
||||
++os;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printf ("\nstatic FixedFont fonts[] = {\n%s};\n", table.c_str ());
|
||||
|
||||
printf ("\n} // namespace lay\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
TEMPLATE = app
|
||||
TARGET = fontgen
|
||||
|
||||
SOURCES = fontgen.cc
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ SUBDIRS = \
|
|||
lib \
|
||||
plugins \
|
||||
buddies \
|
||||
fontgen \
|
||||
|
||||
LANG_DEPENDS =
|
||||
MAIN_DEPENDS =
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -275,7 +275,7 @@ Bitmap::merge (const lay::Bitmap *from, int dx, int dy)
|
|||
}
|
||||
|
||||
void
|
||||
Bitmap::fill_pattern (int y, int x, const uint32_t *pp, unsigned int n)
|
||||
Bitmap::fill_pattern (int y, int x, const uint32_t *pp, unsigned int stride, unsigned int n)
|
||||
{
|
||||
if (x < int (m_width)) {
|
||||
|
||||
|
|
@ -290,41 +290,44 @@ Bitmap::fill_pattern (int y, int x, const uint32_t *pp, unsigned int n)
|
|||
|
||||
while (n > 0 && y >= 0) {
|
||||
|
||||
uint32_t p = *pp;
|
||||
for (unsigned int s = 0; s < stride; ++s) {
|
||||
|
||||
int x1 = x;
|
||||
int x1 = x + s * 32;
|
||||
|
||||
if (x1 < 0) {
|
||||
if (x1 <= -32) {
|
||||
return;
|
||||
}
|
||||
p >>= (unsigned int)-x1;
|
||||
x1 = 0;
|
||||
}
|
||||
uint32_t p = *pp++;
|
||||
|
||||
if (p) {
|
||||
|
||||
unsigned int bx = ((unsigned int) x1) & ~(32 - 1);
|
||||
|
||||
uint32_t *sl = scanline (y);
|
||||
sl += bx / 32;
|
||||
|
||||
*sl |= (p << ((unsigned int)x1 - bx));
|
||||
|
||||
if ((unsigned int)x1 > bx) {
|
||||
|
||||
bx += 32;
|
||||
++sl;
|
||||
|
||||
if (bx < m_width) {
|
||||
*sl |= (p >> (bx - (unsigned int)x1));
|
||||
if (x1 < 0) {
|
||||
if (x1 <= -32) {
|
||||
return;
|
||||
}
|
||||
|
||||
p >>= (unsigned int)-x1;
|
||||
x1 = 0;
|
||||
}
|
||||
|
||||
if (p) {
|
||||
|
||||
unsigned int bx = ((unsigned int) x1) & ~(32 - 1);
|
||||
|
||||
uint32_t *sl = scanline (y);
|
||||
sl += bx / 32;
|
||||
|
||||
*sl |= (p << ((unsigned int)x1 - bx));
|
||||
|
||||
if ((unsigned int)x1 > bx) {
|
||||
|
||||
bx += 32;
|
||||
++sl;
|
||||
|
||||
if (bx < m_width) {
|
||||
*sl |= (p >> (bx - (unsigned int)x1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
++pp;
|
||||
--n;
|
||||
--y;
|
||||
|
||||
|
|
@ -851,7 +854,7 @@ Bitmap::render_text (const lay::RenderText &text)
|
|||
size_t cc = c; // to suppress a compiler warning ..
|
||||
if (c >= ff.first_char () && cc < size_t (ff.n_chars ()) + size_t (ff.first_char ())
|
||||
&& xx > -100.0 && xx < double (width ())) {
|
||||
fill_pattern (int (y + 0.5), int (floor (xx)), ff.data () + (c - ff.first_char ()) * ff.height (), ff.height ());
|
||||
fill_pattern (int (y + 0.5), int (floor (xx)), ff.data () + (c - ff.first_char ()) * ff.height () * ff.stride (), ff.stride (), ff.height ());
|
||||
}
|
||||
|
||||
xx += double (ff.width ());
|
||||
|
|
|
|||
|
|
@ -324,8 +324,10 @@ private:
|
|||
* @param y The scanline
|
||||
* @param x1 The start coordinate
|
||||
* @param p The pattern to use
|
||||
* @param stride The number of words per line
|
||||
* @param n The height (number of lines)
|
||||
*/
|
||||
void fill_pattern (int y, int x, const uint32_t *p, unsigned int n);
|
||||
void fill_pattern (int y, int x, const uint32_t *p, unsigned int stride, unsigned int n);
|
||||
};
|
||||
|
||||
inline bool
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ namespace lay
|
|||
|
||||
int FixedFont::ms_default_font_size = 0;
|
||||
|
||||
FixedFont::FixedFont (unsigned int h, unsigned int lh, unsigned int w, unsigned char c0, unsigned char nc, uint32_t *d)
|
||||
: m_height (h), m_line_height (lh), m_width (w), m_first_char (c0), m_n_chars (nc), mp_data (d)
|
||||
FixedFont::FixedFont (unsigned int h, unsigned int lh, unsigned int w, unsigned char c0, unsigned char nc, uint32_t *d, unsigned int stride)
|
||||
: m_height (h), m_line_height (lh), m_width (w), m_first_char (c0), m_n_chars (nc), mp_data (d), m_stride (stride)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ const FixedFont &
|
|||
FixedFont::get_font (double resolution)
|
||||
{
|
||||
int fs = ms_default_font_size;
|
||||
int od = std::max (1, std::min (int (sizeof (fonts) / sizeof (fonts [0])), int (1.0 / resolution + 0.5))) - 1;
|
||||
int od = std::max (1, std::min (int (sizeof (fonts) / sizeof (fonts [0])) / 3, int (1.0 / resolution + 0.5))) - 1;
|
||||
return fonts [od * 3 + fs];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public:
|
|||
/**
|
||||
* @brief ctor
|
||||
*/
|
||||
FixedFont (unsigned int h, unsigned int lh, unsigned int w, unsigned char c0, unsigned char nc, uint32_t *d);
|
||||
FixedFont (unsigned int h, unsigned int lh, unsigned int w, unsigned char c0, unsigned char nc, uint32_t *d, unsigned int stride);
|
||||
|
||||
/**
|
||||
* @brief Factory
|
||||
|
|
@ -90,11 +90,20 @@ public:
|
|||
return mp_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the stride (number of words per line)
|
||||
*/
|
||||
unsigned int stride () const
|
||||
{
|
||||
return m_stride;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int m_height, m_line_height, m_width;
|
||||
unsigned char m_first_char;
|
||||
unsigned char m_n_chars;
|
||||
uint32_t *mp_data;
|
||||
unsigned int m_stride;
|
||||
static int ms_default_font_size;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue