WiP: remove legacy fonts

This commit is contained in:
Raphael Coeffic
2022-06-11 15:38:08 +02:00
committed by Raphael Coeffic
parent 8d6a7c2da5
commit b40441f0c0
18 changed files with 113 additions and 334 deletions
+2 -1
View File
@@ -146,7 +146,8 @@ lv_indev_state_t encoderState = LV_INDEV_STATE_RELEASED;
void lvglPushEncoderEvent(event_t& evt)
{
if(evt != EVT_KEY_FIRST(KEY_ENTER) && evt != EVT_KEY_BREAK(KEY_ENTER) && evt != EVT_ROTARY_LEFT && evt != EVT_ROTARY_RIGHT)
if (evt != EVT_KEY_FIRST(KEY_ENTER) && evt != EVT_KEY_BREAK(KEY_ENTER) &&
evt != EVT_ROTARY_LEFT && evt != EVT_ROTARY_RIGHT)
return;
encoderEvent = evt;
+1 -1
View File
@@ -22,8 +22,8 @@
#ifndef _LVGLWRAPPER_H_
#define _LVGLWRAPPER_H_
#include <lvgl/lvgl.h>
#include "opentx_types.h"
#include "lvgl/lvgl.h"
extern lv_color_t makeLvColor(uint32_t colorFlags);
#if defined(HARDWARE_TOUCH)
+25 -169
View File
@@ -21,183 +21,39 @@
#include "opentx.h"
const uint16_t font_xxs_specs[] = {
#include "font_9.specs"
};
const unsigned char font_xxs[] = {
#include "font_9.lbm"
};
#if LCD_H > 272
#if defined(BOOT)
const uint16_t font_std_en_specs[] = {
#include "font_17en.specs"
};
const unsigned char font_std_en[] = {
#include "font_17en.lbm"
};
static const lv_font_t* lvglFontTable[FONTS_COUNT] = {
LV_FONT_DEFAULT, // FONT_STD_INDEX
#if !defined(BOOT)
&lv_font_roboto_bold_16, // FONT_BOLD_INDEX
&lv_font_roboto_9, // FONT_XXS_INDEX
&lv_font_roboto_13, // FONT_XS_INDEX
&lv_font_roboto_24, // FONT_L_INDEX
&lv_font_roboto_bold_32, // FONT_XL_INDEX
&lv_font_roboto_bold_64, // FONT_XXL_INDEX
#endif
const uint16_t font_xs_specs[] = {
#include "font_15.specs"
};
const unsigned char font_xs[] = {
#include "font_15.lbm"
};
const uint16_t font_std_specs[] = {
#include "font_17.specs"
};
const unsigned char font_std[] = {
#include "font_17.lbm"
};
const uint16_t font_bold_specs[] = {
#include "font_bold17.specs"
};
const unsigned char font_bold[] = {
#include "font_bold17.lbm"
};
#else // LCD_H <= 272
#if defined(BOOT)
const uint16_t font_std_en_specs[] = {
#include "font_16en.specs"
};
const unsigned char font_std_en[] = {
#include "font_16en.lbm"
};
#endif
const uint16_t font_xs_specs[] = {
#include "font_13.specs"
};
const unsigned char font_xs[] = {
#include "font_13.lbm"
};
const uint16_t font_std_specs[] = {
#include "font_16.specs"
};
const unsigned char font_std[] = {
#include "font_16.lbm"
};
const uint16_t font_bold_specs[] = {
#include "font_bold16.specs"
};
const unsigned char font_bold[] = {
#include "font_bold16.lbm"
};
#endif // LCD_H > 272
const uint16_t font_l_specs[] = {
#include "font_24.specs"
};
const unsigned char font_l[] = {
#include "font_24.lbm"
};
const uint16_t font_xl_specs[] = {
#include "font_32.specs"
};
const unsigned char font_xl[] = {
#include "font_32.lbm"
};
const uint16_t font_xxl_specs[] = {
#include "font_64.specs"
};
const unsigned char font_xxl[] = {
#include "font_64.lbm"
};
#if defined(BOOT)
// -2 for: overall length and last boundary
const uint16_t fontCharactersTable[FONTS_COUNT] = { sizeof(font_std_en_specs)/2-2 };
const uint16_t * const fontspecsTable[FONTS_COUNT] = { font_std_en_specs };
const uint8_t * fontsTable[FONTS_COUNT] = { font_std_en };
const int fontsSizeTable[FONTS_COUNT] = { sizeof(font_std_en) };
#else
// -2 for: overall length and last boundary
const uint16_t fontCharactersTable[FONTS_COUNT] = {
sizeof(font_std_specs)/2-2, sizeof(font_bold_specs)/2-2, sizeof(font_xxs_specs)/2-2,
sizeof(font_xs_specs)/2-2, sizeof(font_l_specs)/2-2, sizeof(font_xl_specs)/2-2,
sizeof(font_xxl_specs)/2-2
};
const uint16_t *const fontspecsTable[FONTS_COUNT] = {
font_std_specs, font_bold_specs, font_xxs_specs, font_xs_specs,
font_l_specs, font_xl_specs, font_xxl_specs
};
const uint8_t *fontsTable[FONTS_COUNT] = {
font_std, font_bold, font_xxs, font_xs, font_l, font_xl, font_xxl
};
const int fontsSizeTable[FONTS_COUNT] = {
sizeof(font_std), sizeof(font_bold), sizeof(font_xxs),
sizeof(font_xs), sizeof(font_l), sizeof(font_xl),
sizeof(font_xxl)
};
#endif
uint8_t * decompressFont(const uint8_t * font, unsigned len)
const lv_font_t* getFont(LcdFlags flags)
{
int width = 0;
int height = 0;
uint8_t* raw_font = BitmapBuffer::loadFont(font, len, width, height);
if (!raw_font) {
return nullptr;
}
size_t font_size = width * height;
uint8_t * buf = (uint8_t *)malloc(font_size + 4);
((uint16_t*)buf)[0] = (uint16_t)width;
((uint16_t*)buf)[1] = (uint16_t)height;
#if defined(LCD_VERTICAL_INVERT) && 0
uint8_t* src = raw_font + font_size - 1;
for(uint8_t* dst = buf + 4; src >= raw_font; --src, ++dst) {
*dst = 0xFF - *src;
}
#if defined(BOOT)
return LV_FONT_DEFAULT;
#else
uint8_t* src = raw_font;
for(uint8_t* dst = buf + 4; src != raw_font + font_size; ++src, ++dst) {
*dst = 0xFF - *src;
}
auto fontIndex = FONT_INDEX(flags);
if (fontIndex >= FONTS_COUNT) return LV_FONT_DEFAULT;
return lvglFontTable[fontIndex];
#endif
return buf;
}
void loadFonts()
uint8_t getFontHeight(LcdFlags flags)
{
static bool fontsLoaded = false;
if (fontsLoaded)
return;
auto font = getFont(flags);
return lv_font_get_line_height(font);
}
#if defined(BOOT)
fontsTable[0] = decompressFont(fontsTable[0], fontsSizeTable[0]);
#else
for (int i = 0; i < FONTS_COUNT; i++) {
fontsTable[i] = decompressFont(fontsTable[i], fontsSizeTable[i]);
}
#endif
fontsLoaded = true;
int getTextWidth(const char * s, int len, LcdFlags flags)
{
auto font = getFont(flags);
lv_coord_t letter_space = 0;
if (!len) len = strlen(s);
return lv_txt_get_width(s, len, font, letter_space, LV_TEXT_FLAG_EXPAND);
}
-24
View File
@@ -1,24 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* 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.
*/
#pragma once
void loadFonts();
@@ -57,15 +57,14 @@ void Layout::checkEvents()
LayoutBase::checkEvents();
adjustLayout();
uint32_t now = RTOS_GET_MS();
if (now - lastRefresh >= LAYOUT_REFRESH) {
lastRefresh = now;
invalidate();
#if defined(DEBUG_WINDOWS)
TRACE_WINDOWS("# %s refresh: %s", factory->getId(), getWindowDebugString().c_str());
#endif
}
// uint32_t now = RTOS_GET_MS();
// if (now - lastRefresh >= LAYOUT_REFRESH) {
// lastRefresh = now;
// invalidate();
// #if defined(DEBUG_WINDOWS)
// TRACE_WINDOWS("# %s refresh: %s", factory->getId(), getWindowDebugString().c_str());
// #endif
// }
}
void Layout::setTrimsVisible(bool visible)
-58
View File
@@ -22,64 +22,6 @@
#include "lcd.h"
#include "opentx.h"
uint8_t getMappedChar(uint8_t c)
{
uint8_t result;
result = c - 0x20;
// TRACE("getMappedChar '%c' (0x%x) = %d", c, c, result);
return result;
}
int getFontPatternWidth(const uint16_t * spec, int index)
{
return spec[index + 2] - spec[index + 1];
}
int getCharWidth(uint8_t c, const uint16_t * spec)
{
return getFontPatternWidth(spec, getMappedChar(c));
}
uint8_t getFontHeight(LcdFlags flags)
{
uint32_t fontindex = FONT_INDEX(flags);
return fontspecsTable[fontindex][0];
}
int getTextWidth(const char * s, int len, LcdFlags flags)
{
const uint16_t * specs = fontspecsTable[FONT_INDEX(flags)];
int result = 0;
for (int i = 0; len == 0 || i < len; ++i) {
unsigned c = uint8_t(*s);
if (!c) {
break;
}
else if (c >= 0xFE) { // CJK marker
s++;
c = uint8_t(*s) + ((c & 0x01) << 8) - 1;
if (c >= 0x100)
c -= 1;
c += CJK_FIRST_LETTER_INDEX;
result += getFontPatternWidth(specs, c) + 1;
}
else if ((c >= 0x20u) && (c < fontCharactersTable[FONT_INDEX(flags)] + 0x20u)) {
result += getCharWidth(c, specs);
}
else {
TRACE("char out-of bound: 0x%X", c);
}
++s;
}
return result;
}
void lcdSetContrast()
{
lcdSetRefVolt(g_eeGeneral.contrast);
-1
View File
@@ -24,7 +24,6 @@
#include "bitmapbuffer.h"
#include "opentx_types.h"
#include "libopenui_globals.h"
#if LCD_W >= 480
#define LCD_COLS 40
+3 -12
View File
@@ -40,19 +40,10 @@ SelectFabButton::SelectFabButton(FormGroup* parent, coord_t x, coord_t y,
void SelectFabButton::paint(BitmapBuffer* dc)
{
FabButton::paint(dc);
auto pos = title.find('\n');
auto y_pos = FAB_BUTTON_SIZE;
dc->drawSizedText(width() / 2, y_pos,
title.c_str(), pos,
COLOR2FLAGS(WHITE) | CENTERED | VCENTERED);
if (pos != std::string::npos) {
y_pos += PAGE_LINE_HEIGHT;
dc->drawSizedText(width() / 2, y_pos, title.substr(pos+1).c_str(),
255, COLOR2FLAGS(WHITE) | CENTERED | VCENTERED);
}
dc->drawSizedText(width() / 2, FAB_BUTTON_SIZE,
title.c_str(), title.size(),
COLOR2FLAGS(WHITE) | CENTERED);
if (hasFocus()) {
dc->drawSolidRect(0, 0, width(), height(), 2, COLOR2FLAGS(WHITE));