2019-09-03 11:58:42 +02:00
|
|
|
/*
|
|
|
|
* libeg/text.c
|
|
|
|
* Text drawing functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Christoph Pfisterer
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of Christoph Pfisterer nor the names of the
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2020-04-08 12:04:54 +02:00
|
|
|
//Slice 2011 - 2016 numerous improvements, 2020 full rewritten for c++
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-04-07 21:48:36 +02:00
|
|
|
extern "C" {
|
|
|
|
#include <Protocol/GraphicsOutput.h>
|
|
|
|
}
|
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
#include "libegint.h"
|
2019-12-27 18:01:40 +01:00
|
|
|
#include "nanosvg.h"
|
2020-03-31 17:59:35 +02:00
|
|
|
#include "VectorGraphics.h"
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
//#include "egemb_font.h"
|
|
|
|
//#define FONT_CELL_WIDTH (7)
|
|
|
|
//#define FONT_CELL_HEIGHT (12)
|
|
|
|
|
|
|
|
#ifndef DEBUG_ALL
|
|
|
|
#define DEBUG_TEXT 0
|
|
|
|
#else
|
|
|
|
#define DEBUG_TEXT DEBUG_ALL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DEBUG_TEXT == 0
|
|
|
|
#define DBG(...)
|
|
|
|
#else
|
|
|
|
#define DBG(...) DebugLog(DEBUG_TEXT, __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
2020-04-07 21:48:36 +02:00
|
|
|
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL SemiWhitePixel = {0xFF, 0xFF, 0xFF, 0xD2}; //semitransparent white
|
2020-03-10 14:00:02 +01:00
|
|
|
NSVGfontChain *fontsDB = NULL;
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Text rendering
|
|
|
|
//
|
2020-04-07 21:48:36 +02:00
|
|
|
//it is not good for vector theme
|
|
|
|
//it will be better to sum each letter width for the chosen font
|
|
|
|
// so one more parameter is TextStyle
|
2020-04-08 12:04:54 +02:00
|
|
|
VOID XTheme::MeasureText(IN const XStringW& Text, OUT INTN *Width, OUT INTN *Height)
|
2020-03-22 11:48:13 +01:00
|
|
|
{
|
2020-04-09 15:04:12 +02:00
|
|
|
INTN ScaledWidth = CharWidth;
|
|
|
|
INTN ScaledHeight = FontHeight;
|
|
|
|
if (Scale != 0.f) {
|
|
|
|
ScaledWidth = (INTN)(CharWidth * Scale);
|
|
|
|
ScaledHeight = (INTN)(FontHeight * Scale);
|
|
|
|
}
|
2020-03-22 11:48:13 +01:00
|
|
|
if (Width != NULL)
|
2020-04-09 15:04:12 +02:00
|
|
|
*Width = StrLen(Text.wc_str()) * ((FontWidth > ScaledWidth) ? FontWidth : ScaledWidth);
|
2020-03-22 11:48:13 +01:00
|
|
|
if (Height != NULL)
|
2020-04-09 15:04:12 +02:00
|
|
|
*Height = ScaledHeight;
|
2020-03-22 11:48:13 +01:00
|
|
|
}
|
2020-04-07 21:48:36 +02:00
|
|
|
void XTheme::LoadFontImage(IN BOOLEAN UseEmbedded, IN INTN Rows, IN INTN Cols)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status = EFI_NOT_FOUND;
|
|
|
|
XImage NewImage; //tempopary image from file
|
|
|
|
|
|
|
|
INTN ImageWidth, ImageHeight;
|
|
|
|
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *PixelPtr;
|
|
|
|
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *FontPtr;
|
|
|
|
EFI_GRAPHICS_OUTPUT_BLT_PIXEL FirstPixel;
|
|
|
|
BOOLEAN isKorean = (gLanguage == korean);
|
|
|
|
XStringW fontFilePath;
|
|
|
|
const XStringW& commonFontDir = L"EFI\\CLOVER\\font"_XSW;
|
|
|
|
|
|
|
|
if (IsEmbeddedTheme() && !isKorean) { //or initial screen before theme init
|
2020-04-09 15:04:12 +02:00
|
|
|
Status = NewImage.FromPNG(ACCESS_EMB_DATA(emb_font_data), ACCESS_EMB_SIZE(emb_font_data)); //always success
|
2020-04-07 21:48:36 +02:00
|
|
|
MsgLog("Using embedded font\n");
|
|
|
|
} else if (isKorean){
|
|
|
|
Status = NewImage.LoadXImage(ThemeDir, L"FontKorean.png"_XSW);
|
|
|
|
MsgLog("Loading korean font from ThemeDir: %s\n", strerror(Status));
|
2020-04-09 15:04:12 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
|
|
|
CharWidth = 22; //standard for korean
|
|
|
|
} else {
|
2020-04-07 21:48:36 +02:00
|
|
|
MsgLog("...using english\n");
|
|
|
|
gLanguage = english;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-09 15:04:12 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
//not loaded, use common
|
|
|
|
Rows = 16; //standard for english
|
|
|
|
Cols = 16;
|
|
|
|
Status = NewImage.LoadXImage(ThemeDir, FontFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR(Status)) {
|
2020-04-07 21:48:36 +02:00
|
|
|
//then take from common font folder
|
|
|
|
// fontFilePath = SWPrintf(L"%s\\%s", commonFontDir, isKorean ? L"FontKorean.png" : ThemeX.FontFileName.data());
|
|
|
|
fontFilePath = commonFontDir + FontFileName;
|
|
|
|
Status = NewImage.LoadXImage(SelfRootDir, fontFilePath);
|
2020-04-09 15:04:12 +02:00
|
|
|
//else use embedded even if it is not embedded
|
2020-04-07 21:48:36 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
2020-04-09 15:04:12 +02:00
|
|
|
Status = NewImage.FromPNG(ACCESS_EMB_DATA(emb_font_data), ACCESS_EMB_SIZE(emb_font_data));
|
|
|
|
}
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
MsgLog("No font found!\n");
|
|
|
|
return;
|
2020-04-07 21:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageWidth = NewImage.GetWidth();
|
|
|
|
// DBG("ImageWidth=%lld\n", ImageWidth);
|
|
|
|
ImageHeight = NewImage.GetHeight();
|
|
|
|
// DBG("ImageHeight=%lld\n", ImageHeight);
|
|
|
|
PixelPtr = NewImage.GetPixelPtr(0,0);
|
|
|
|
|
|
|
|
FontImage.setSizeInPixels(ImageWidth * Rows, ImageHeight / Rows);
|
|
|
|
FontPtr = FontImage.GetPixelPtr(0,0);
|
|
|
|
|
|
|
|
FontWidth = ImageWidth / Cols;
|
|
|
|
FontHeight = ImageHeight / Rows;
|
|
|
|
TextHeight = FontHeight + (int)(TEXT_YMARGIN * 2 * Scale);
|
2020-04-09 15:04:12 +02:00
|
|
|
// if (!isKorean) {
|
|
|
|
// CharWidth = FontWidth; //there is default value anyway
|
|
|
|
// }
|
2020-04-07 21:48:36 +02:00
|
|
|
|
|
|
|
FirstPixel = *PixelPtr;
|
|
|
|
for (INTN y = 0; y < Rows; y++) {
|
|
|
|
for (INTN j = 0; j < FontHeight; j++) {
|
|
|
|
INTN Ypos = ((j * Rows) + y) * ImageWidth;
|
|
|
|
for (INTN x = 0; x < ImageWidth; x++) {
|
|
|
|
if (
|
|
|
|
//First pixel is accounting as "blue key"
|
|
|
|
(PixelPtr->Blue == FirstPixel.Blue) &&
|
|
|
|
(PixelPtr->Green == FirstPixel.Green) &&
|
|
|
|
(PixelPtr->Red == FirstPixel.Red)
|
|
|
|
) {
|
|
|
|
PixelPtr->Reserved = 0; //if a pixel has same color as first pixel then it will be transparent
|
2020-04-16 13:04:24 +02:00
|
|
|
//} else if (ThemeX.DarkEmbedded) {
|
2020-04-17 16:50:31 +02:00
|
|
|
} else if (ThemeX.embedded && !ThemeX.Daylight) {
|
2020-04-07 21:48:36 +02:00
|
|
|
*PixelPtr = SemiWhitePixel; //special case to change a text to semi white, not blue pixels
|
|
|
|
}
|
|
|
|
FontPtr[Ypos + x] = *PixelPtr++; //not (x, YPos) !!!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID XTheme::PrepareFont()
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
2020-04-07 21:48:36 +02:00
|
|
|
|
|
|
|
TextHeight = FontHeight + (int)(TEXT_YMARGIN * 2 * Scale);
|
|
|
|
if (TypeSVG) {
|
2020-03-29 09:14:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-04-07 21:48:36 +02:00
|
|
|
|
|
|
|
// load the font
|
2020-04-08 09:32:26 +02:00
|
|
|
if (FontImage.isEmpty()) {
|
2020-04-07 21:48:36 +02:00
|
|
|
DBG("load font image type %d\n", Font);
|
|
|
|
LoadFontImage(TRUE, 16, 16); //anyway success
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FontImage.isEmpty()) {
|
|
|
|
if (Font == FONT_GRAY) {
|
|
|
|
//invert the font. embedded is dark
|
2020-04-08 09:32:26 +02:00
|
|
|
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *p = FontImage.GetPixelPtr(0,0);
|
|
|
|
for (INTN Height = 0; Height < FontImage.GetHeight(); Height++){
|
|
|
|
for (INTN Width = 0; Width < FontImage.GetWidth(); Width++, p++){
|
2020-04-07 21:48:36 +02:00
|
|
|
p->Blue ^= 0xFF;
|
|
|
|
p->Green ^= 0xFF;
|
|
|
|
p->Red ^= 0xFF;
|
|
|
|
//p->a = 0xFF; //huh! dont invert opacity
|
|
|
|
}
|
|
|
|
}
|
2020-04-08 09:32:26 +02:00
|
|
|
// FontImage.Draw(0, 300, 0.6f); //for debug purpose
|
2020-04-07 21:48:36 +02:00
|
|
|
}
|
|
|
|
DBG("Font %d prepared WxH=%lldx%lld CharWidth=%lld\n", Font, FontWidth, FontHeight, CharWidth);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
DBG("Failed to load font\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//search pixel similar to first
|
|
|
|
inline bool SamePix(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Ptr, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& FirstPixel)
|
|
|
|
{
|
|
|
|
//compare with first pixel of the array top-left point [0][0]
|
|
|
|
return ((Ptr.Red >= FirstPixel.Red - (FirstPixel.Red >> 2)) &&
|
|
|
|
(Ptr.Red <= FirstPixel.Red + (FirstPixel.Red >> 2)) &&
|
|
|
|
(Ptr.Green >= FirstPixel.Green - (FirstPixel.Green >> 2)) &&
|
|
|
|
(Ptr.Green <= FirstPixel.Green + (FirstPixel.Green >> 2)) &&
|
|
|
|
(Ptr.Blue >= FirstPixel.Blue - (FirstPixel.Blue >> 2)) &&
|
|
|
|
(Ptr.Blue <= FirstPixel.Blue + (FirstPixel.Blue >> 2)) &&
|
|
|
|
(Ptr.Reserved == FirstPixel.Reserved)); //hack for transparent fonts
|
|
|
|
}
|
|
|
|
|
|
|
|
//used for proportional fonts in raster themes
|
|
|
|
//search empty column from begin Step=1 or from end Step=-1 in the input buffer
|
|
|
|
// empty means similar to FirstPixel
|
2020-04-22 01:27:01 +02:00
|
|
|
INTN XTheme::GetEmpty(const XImage& Buffer, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& FirstPixel, INTN MaxWidth, INTN Start, INTN Step)
|
2020-04-07 21:48:36 +02:00
|
|
|
{
|
|
|
|
INTN m, i;
|
|
|
|
// INTN Shift = (Step > 0)?0:1;
|
2020-04-22 01:27:01 +02:00
|
|
|
m = MaxWidth;
|
2020-04-07 21:48:36 +02:00
|
|
|
if (Step == 1) {
|
|
|
|
for (INTN j = 0; j < FontHeight; j++) {
|
2020-04-22 01:27:01 +02:00
|
|
|
for (i = 0; i < MaxWidth; i++) {
|
2020-04-07 21:48:36 +02:00
|
|
|
if (!SamePix(Buffer.GetPixel(Start + i,j), FirstPixel)) { //found not empty pixel
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m = MIN(m, i); //for each line to find minimum
|
|
|
|
if (m == 0) break;
|
|
|
|
}
|
|
|
|
} else { // go back
|
|
|
|
for (INTN j = 0; j < FontHeight; j++) {
|
2020-04-22 01:27:01 +02:00
|
|
|
for (i = 1; i <= MaxWidth; i++) {
|
|
|
|
if (!SamePix(Buffer.GetPixel(Start - i,j), FirstPixel)) { //found not empty pixel
|
2020-04-07 21:48:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-04-22 01:27:01 +02:00
|
|
|
m = MIN(m, i); //for each line to find minimum
|
|
|
|
if (m == 0) break;
|
2020-04-07 21:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
2019-09-03 11:58:42 +02:00
|
|
|
|
2020-04-30 08:03:56 +02:00
|
|
|
INTN XTheme::RenderText(IN const XString8& Text, OUT XImage* CompImage_ptr,
|
2020-04-15 23:04:33 +02:00
|
|
|
IN INTN PosX, IN INTN PosY, IN UINTN Cursor, INTN textType, float textScale)
|
2020-04-08 11:45:36 +02:00
|
|
|
{
|
|
|
|
const XStringW& UTF16Text = XStringW().takeValueFrom(Text.c_str());
|
2020-04-09 15:04:12 +02:00
|
|
|
return RenderText(UTF16Text, CompImage_ptr, PosX, PosY, Cursor, textType, textScale);
|
2020-04-08 11:45:36 +02:00
|
|
|
}
|
|
|
|
|
2020-04-07 21:48:36 +02:00
|
|
|
INTN XTheme::RenderText(IN const XStringW& Text, OUT XImage* CompImage_ptr,
|
2020-04-15 23:04:33 +02:00
|
|
|
IN INTN PosX, IN INTN PosY, IN UINTN Cursor, INTN textType, float textScale)
|
2019-09-03 11:58:42 +02:00
|
|
|
{
|
2020-03-31 17:59:35 +02:00
|
|
|
XImage& CompImage = *CompImage_ptr;
|
2020-04-07 21:48:36 +02:00
|
|
|
|
|
|
|
EFI_GRAPHICS_OUTPUT_BLT_PIXEL FontPixel;
|
|
|
|
EFI_GRAPHICS_OUTPUT_BLT_PIXEL FirstPixel;
|
2020-04-15 23:04:33 +02:00
|
|
|
UINTN TextLength;
|
2020-04-09 15:04:12 +02:00
|
|
|
UINTN Cho = 0, Jong = 0, Joong = 0;
|
2020-04-07 21:48:36 +02:00
|
|
|
INTN LeftSpace, RightSpace;
|
2020-03-23 20:10:16 +01:00
|
|
|
|
2020-04-07 21:48:36 +02:00
|
|
|
if (TypeSVG) {
|
2020-03-31 17:59:35 +02:00
|
|
|
return renderSVGtext(&CompImage, PosX, PosY, textType, Text, Cursor);
|
2020-03-22 11:48:13 +01:00
|
|
|
}
|
|
|
|
|
2020-04-09 15:04:12 +02:00
|
|
|
if (textScale == 0.f) {
|
|
|
|
textScale = 1.f;
|
|
|
|
}
|
|
|
|
INTN CharScaledWidth = (INTN)(CharWidth * textScale);
|
|
|
|
INTN FontScaledWidth = (INTN)(FontWidth * textScale); //FontWidth should be scaled as well?
|
2019-09-03 11:58:42 +02:00
|
|
|
// clip the text
|
2020-04-09 15:04:12 +02:00
|
|
|
// TextLength = StrLenInWChar(Text.wc_str()); //it must be UTF16 length
|
|
|
|
TextLength = StrLen(Text.wc_str());
|
|
|
|
DBG("text to render %ls length %lld\n", Text.wc_str(), TextLength);
|
2020-04-07 21:48:36 +02:00
|
|
|
if (FontImage.isEmpty()) {
|
|
|
|
PrepareFont(); //at the boot screen there is embedded font
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-04-07 21:48:36 +02:00
|
|
|
|
2020-04-09 15:04:12 +02:00
|
|
|
DBG("TextLength =%lld PosX=%lld PosY=%lld\n", TextLength, PosX, PosY);
|
2020-04-07 21:48:36 +02:00
|
|
|
FirstPixel = CompImage.GetPixel(0,0);
|
|
|
|
FontPixel = FontImage.GetPixel(0,0);
|
2020-04-09 15:04:12 +02:00
|
|
|
UINT16 c0 = 0x20;
|
|
|
|
INTN RealWidth = CharScaledWidth;
|
|
|
|
INTN Shift = (FontScaledWidth - CharScaledWidth) / 2;
|
|
|
|
if (Shift < 0) {
|
|
|
|
Shift = 0;
|
|
|
|
}
|
2020-04-08 09:32:26 +02:00
|
|
|
DBG("FontWidth=%lld, CharWidth=%lld\n", FontWidth, RealWidth);
|
2020-04-09 15:04:12 +02:00
|
|
|
|
|
|
|
EG_RECT Area; //area is scaled
|
2020-04-07 21:48:36 +02:00
|
|
|
Area.YPos = PosY; // not sure
|
2020-04-09 15:04:12 +02:00
|
|
|
Area.Height = TextHeight;
|
|
|
|
EG_RECT Bukva; //bukva is not scaled place
|
2020-04-07 21:48:36 +02:00
|
|
|
Bukva.YPos = 0;
|
|
|
|
Bukva.Width = FontWidth;
|
|
|
|
Bukva.Height = FontHeight;
|
2020-04-08 11:45:36 +02:00
|
|
|
DBG("codepage=%llx, asciiPage=%x\n", GlobalConfig.Codepage, AsciiPageSize);
|
2020-04-15 23:04:33 +02:00
|
|
|
for (UINTN i = 0; i < TextLength && c0 != 0; i++) {
|
2020-04-09 18:32:46 +02:00
|
|
|
UINT16 c = Text.wc_str()[i]; //including UTF8 -> UTF16 conversion
|
2020-04-17 14:27:38 +02:00
|
|
|
DBG("initial char to render 0x%hx\n", c); //good
|
2020-04-08 11:45:36 +02:00
|
|
|
if (gLanguage != korean) { //russian Codepage = 0x410
|
|
|
|
if (c >= 0x410 && c < 0x450) {
|
|
|
|
//we have russian raster fonts with chars at 0xC0
|
|
|
|
c -= 0x350;
|
|
|
|
} else {
|
|
|
|
INTN c2 = (c >= GlobalConfig.Codepage) ? (c - GlobalConfig.Codepage + AsciiPageSize) : c; //International letters
|
|
|
|
c = c2 & 0xFF; //this maximum raster font size
|
|
|
|
}
|
2020-04-17 14:27:38 +02:00
|
|
|
// DBG("char to render 0x%hhx\n", c);
|
2020-04-07 21:48:36 +02:00
|
|
|
if (Proportional) {
|
2020-04-08 09:32:26 +02:00
|
|
|
//find spaces {---comp--__left__|__right__--char---}
|
2019-09-03 11:58:42 +02:00
|
|
|
if (c0 <= 0x20) { // space before or at buffer edge
|
|
|
|
LeftSpace = 2;
|
|
|
|
} else {
|
2020-04-22 01:27:01 +02:00
|
|
|
LeftSpace = GetEmpty(CompImage, FirstPixel, RealWidth, PosX, -1);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-04-07 21:48:36 +02:00
|
|
|
if (c <= 0x20) { //new space will be half font width
|
2019-09-03 11:58:42 +02:00
|
|
|
RightSpace = 1;
|
2020-04-09 15:04:12 +02:00
|
|
|
RealWidth = (CharScaledWidth >> 1) + 1;
|
2019-09-03 11:58:42 +02:00
|
|
|
} else {
|
2020-04-22 01:27:01 +02:00
|
|
|
RightSpace = GetEmpty(FontImage, FontPixel, FontWidth, c * FontWidth, 1); //not scaled yet
|
2020-04-07 21:48:36 +02:00
|
|
|
if (RightSpace >= FontWidth) {
|
2019-09-03 11:58:42 +02:00
|
|
|
RightSpace = 0; //empty place for invisible characters
|
|
|
|
}
|
2020-04-09 15:04:12 +02:00
|
|
|
RealWidth = CharScaledWidth - (int)(RightSpace * textScale); //a part of char
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LeftSpace = 2;
|
2020-04-09 15:04:12 +02:00
|
|
|
RightSpace = Shift;
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-04-09 15:04:12 +02:00
|
|
|
LeftSpace = (int)(LeftSpace * textScale); //was not scaled yet
|
|
|
|
//RightSpace will not be scaled
|
|
|
|
// RealWidth are scaled now
|
|
|
|
DBG(" RealWidth = %lld LeftSpace = %lld RightSpace = %lld\n", RealWidth, LeftSpace, RightSpace);
|
|
|
|
c0 = c; //remember old value
|
2020-04-07 21:48:36 +02:00
|
|
|
if (PosX + RealWidth > CompImage.GetWidth()) {
|
2020-04-09 15:04:12 +02:00
|
|
|
DBG("no more place for character\n");
|
2019-09-03 11:58:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2020-04-08 11:45:36 +02:00
|
|
|
|
2020-04-07 21:48:36 +02:00
|
|
|
Area.XPos = PosX + 2 - LeftSpace;
|
|
|
|
Area.Width = RealWidth;
|
|
|
|
Bukva.XPos = c * FontWidth + RightSpace;
|
2020-04-09 15:04:12 +02:00
|
|
|
DBG("place [%lld,%lld,%lld,%lld], bukva [%lld,%lld,%lld,%lld]\n",
|
|
|
|
Area.XPos, Area.YPos, Area.Width, Area.Height,
|
|
|
|
Bukva.XPos, Bukva.YPos, Bukva.Width, Bukva.Height);
|
|
|
|
|
|
|
|
CompImage.Compose(Area, Bukva, FontImage, false, textScale);
|
2020-04-08 09:32:26 +02:00
|
|
|
// CompImage.CopyRect(FontImage, Area, Bukva);
|
2019-09-03 11:58:42 +02:00
|
|
|
if (i == Cursor) {
|
|
|
|
c = 0x5F;
|
2020-04-07 21:48:36 +02:00
|
|
|
Bukva.XPos = c * FontWidth + RightSpace;
|
2020-04-09 15:04:12 +02:00
|
|
|
CompImage.Compose(Area, Bukva, FontImage, false, textScale);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
2020-04-07 21:48:36 +02:00
|
|
|
PosX += RealWidth - LeftSpace + 2; //next char position
|
2019-09-03 11:58:42 +02:00
|
|
|
} else {
|
2020-04-07 21:48:36 +02:00
|
|
|
//
|
|
|
|
//Slice - I am not sure in any of this digits
|
|
|
|
//someone knowning korean should revise this
|
2019-09-03 11:58:42 +02:00
|
|
|
//
|
2020-04-08 11:45:36 +02:00
|
|
|
UINT16 c1 = c;
|
2019-09-03 11:58:42 +02:00
|
|
|
if ((c >= 0x20) && (c <= 0x7F)) {
|
|
|
|
c1 = ((c - 0x20) >> 4) * 28 + (c & 0x0F);
|
|
|
|
Cho = c1;
|
|
|
|
Shift = 12;
|
|
|
|
} else if ((c < 0x20) || ((c > 0x7F) && (c < 0xAC00))) {
|
|
|
|
Cho = 0x0E; //just a dot
|
|
|
|
Shift = 8;
|
|
|
|
} else if ((c >= 0xAC00) && (c <= 0xD638)) {
|
|
|
|
//korean
|
2020-04-07 21:48:36 +02:00
|
|
|
|
2019-09-03 11:58:42 +02:00
|
|
|
Shift = 18;
|
|
|
|
c -= 0xAC00;
|
|
|
|
c1 = c / 28;
|
|
|
|
Jong = c % 28;
|
|
|
|
Cho = c1 / 21;
|
|
|
|
Joong = c1 % 21;
|
|
|
|
Cho += 28 * 7;
|
|
|
|
Joong += 28 * 8;
|
|
|
|
Jong += 28 * 9;
|
|
|
|
}
|
2020-04-07 21:48:36 +02:00
|
|
|
|
|
|
|
Area.XPos = PosX;
|
|
|
|
Area.Width = CharWidth;
|
|
|
|
|
|
|
|
// DBG("Cho=%d Joong=%d Jong=%d\n", Cho, Joong, Jong);
|
2019-09-03 11:58:42 +02:00
|
|
|
if (Shift == 18) {
|
2020-04-07 21:48:36 +02:00
|
|
|
Bukva.XPos = Cho * FontWidth + 4;
|
|
|
|
Bukva.YPos = 1;
|
2020-04-09 15:04:12 +02:00
|
|
|
CompImage.Compose(Area, Bukva, FontImage, false, textScale);
|
2019-09-03 11:58:42 +02:00
|
|
|
} else {
|
2020-04-07 21:48:36 +02:00
|
|
|
Area.YPos = PosY + 3;
|
|
|
|
Bukva.XPos = Cho * FontWidth + 2;
|
|
|
|
Bukva.YPos = 0;
|
2020-04-09 15:04:12 +02:00
|
|
|
CompImage.Compose(Area, Bukva, FontImage, false, textScale);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
if (i == Cursor) {
|
|
|
|
c = 99;
|
2020-04-07 21:48:36 +02:00
|
|
|
Bukva.XPos = c * FontWidth + 2;
|
2020-04-09 15:04:12 +02:00
|
|
|
CompImage.Compose(Area, Bukva, FontImage, false, textScale);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
if (Shift == 18) {
|
2020-04-07 21:48:36 +02:00
|
|
|
Area.XPos = PosX + 9;
|
|
|
|
Area.YPos = PosY;
|
|
|
|
Bukva.XPos = Joong * FontWidth + 6;
|
|
|
|
Bukva.YPos = 0;
|
2020-04-09 15:04:12 +02:00
|
|
|
CompImage.Compose(Area, Bukva, FontImage, false, textScale);
|
2020-04-08 12:04:54 +02:00
|
|
|
|
2020-04-07 21:48:36 +02:00
|
|
|
Area.XPos = PosX;
|
|
|
|
Area.YPos = PosY + 9;
|
|
|
|
Bukva.XPos = Jong * FontWidth + 1;
|
2020-04-09 15:04:12 +02:00
|
|
|
CompImage.Compose(Area, Bukva, FontImage, false, textScale);
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
|
2020-04-07 21:48:36 +02:00
|
|
|
PosX += CharWidth; //Shift;
|
2019-09-03 11:58:42 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-07 21:48:36 +02:00
|
|
|
return PosX;
|
|
|
|
}
|
2019-09-03 11:58:42 +02:00
|
|
|
|
|
|
|
/* EOF */
|