WIP: new fixed font bitmaps - needs improvement

This commit is contained in:
Matthias Koefferlein 2019-11-03 17:22:57 +01:00
parent 861a6fdfcc
commit 37e402e9bd
5 changed files with 89395 additions and 25073 deletions

View File

@ -28,6 +28,9 @@
#include <stdio.h>
// The system font to use
static const char *font_name = "Liberation Mono";
/**
* @brief A small utility program to produce the fixed font definition file
* Run this binary and redirect the output to "laybasic/fixedFont.h".
@ -43,19 +46,34 @@ main (int argc, char *argv [])
std::string table;
int sz[] = { 9, 11, 13, 0 };
// 33% increments:
int sz[] = { 9, 11, 13, 16, 21, 27 };
const char *sz_name[] = { "Small", "Medium", "Large", "XLarge", "XXLarge", "XXXLarge" };
int resolutions = 6;
int font_sizes = int (sizeof (sz) / sizeof (sz[0]));
printf("\nconst int ff_resolutions = %d;\n", resolutions);
printf("const int ff_sizes = %d;\n", font_sizes);
printf("\nconst char *ff_size_name (int sz) {\n");
for (int s = 0; s < font_sizes; ++s) {
printf(" if (sz == %d) { return \"%s\"; }\n", s, sz_name [s]);
}
printf(" return \"\";\n}\n");
int os = 1;
for (int r = 1; r <= 6; ++r) {
for (int r = 1; r <= resolutions; ++r) {
for (int s = 0; sz[s] > 0; ++s) {
for (int s = 0; s < font_sizes; ++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::fromLatin1 ("Liberation Mono"), r * sz[s]);
QFont f (QString::fromLatin1 (font_name), r * sz[s]);
f.setStyleStrategy(QFont::StyleStrategy ((f.styleStrategy() & ~QFont::PreferAntialias) | QFont::NoAntialias));
QFontMetrics fm (f);

File diff suppressed because it is too large Load Diff

View File

@ -37,18 +37,30 @@ FixedFont::FixedFont (unsigned int h, unsigned int lh, unsigned int w, unsigned
// .. nothing yet ..
}
int
FixedFont::font_sizes ()
{
return ff_sizes;
}
const char *
FixedFont::font_size_name (int sz)
{
return ff_size_name (sz);
}
void
FixedFont::set_default_font_size (int fs)
{
ms_default_font_size = std::min (2, std::max (0, fs));
ms_default_font_size = std::min (ff_sizes - 1, std::max (0, fs));
}
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])) / 3, int (1.0 / resolution + 0.5))) - 1;
return fonts [od * 3 + fs];
int od = std::max (1, std::min (ff_resolutions, int (1.0 / resolution + 0.5))) - 1;
return fonts [od * ff_sizes + fs];
}
}

View File

@ -27,10 +27,20 @@ public:
*/
static const FixedFont &get_font (double resolution);
/**
* @brief Gets the number of font sizes available
*/
static int font_sizes ();
/**
* @brief Gets the size description ("small", "large", ...)
*/
static const char *font_size_name (int sz);
/**
* @brief Set the default font size
*
* Allowed values are 0 (small), 1 (medium) or 2 (large)
* Allowed values are 0 (small), 1 (medium) or 2 (large) etc.
*/
static void set_default_font_size (int fs);

View File

@ -45,6 +45,8 @@
#include "layWidgets.h"
#include "layFileDialog.h"
#include "layFixedFont.h"
#include "dbHershey.h"
#include <QColorDialog>
@ -1424,6 +1426,11 @@ LayoutViewConfigPage7::LayoutViewConfigPage7 (QWidget *parent)
{
mp_ui = new Ui::LayoutViewConfigPage7 ();
mp_ui->setupUi (this);
mp_ui->default_font_size->clear ();
for (int i = 0; i < lay::FixedFont::font_sizes (); ++i) {
mp_ui->default_font_size->addItem (QString::fromUtf8 (lay::FixedFont::font_size_name (i)));
}
}
LayoutViewConfigPage7::~LayoutViewConfigPage7 ()