Remove schrift from zwidget

This commit is contained in:
Magnus Norddahl 2024-01-08 21:11:56 +01:00
commit 7c6ebc62fa
5 changed files with 0 additions and 1831 deletions

View file

@ -12,8 +12,6 @@ set(ZWIDGET_SOURCES
src/core/pathfill.cpp
src/core/truetypefont.cpp
src/core/truetypefont.h
src/core/schrift/schrift.cpp
src/core/schrift/schrift.h
src/core/picopng/picopng.cpp
src/core/picopng/picopng.h
src/core/nanosvg/nanosvg.cpp
@ -78,7 +76,6 @@ set(ZWIDGET_SDL2_SOURCES
source_group("src" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/.+")
source_group("src\\core" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/core/.+")
source_group("src\\core\\schrift" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/core/schrift/.+")
source_group("src\\core\\picopng" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/core/picopng/.+")
source_group("src\\core\\nanosvg" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/core/nanosvg/.+")
source_group("src\\widgets" REGULAR_EXPRESSION "${CMAKE_CURRENT_SOURCE_DIR}/src/widgets/.+")

View file

@ -8,14 +8,11 @@
#include "core/truetypefont.h"
#include "core/pathfill.h"
#include "window/window.h"
#include "schrift/schrift.h"
#include <vector>
#include <unordered_map>
#include <stdexcept>
#include <cstring>
#define USE_INTERNAL_TTF
class CanvasTexture
{
public:
@ -24,8 +21,6 @@ public:
std::vector<uint32_t> Data;
};
#if defined(USE_INTERNAL_TTF)
class CanvasGlyph
{
public:
@ -125,142 +120,6 @@ public:
std::unordered_map<uint32_t, std::unique_ptr<CanvasGlyph>> glyphs;
};
#else
class CanvasGlyph
{
public:
SFT_Glyph id;
SFT_GMetrics metrics;
double u = 0.0;
double v = 0.0;
double uvwidth = 0.0f;
double uvheight = 0.0f;
std::shared_ptr<CanvasTexture> texture;
};
class CanvasFont
{
public:
CanvasFont(const std::string& fontname, double height) : fontname(fontname), height(height)
{
data = LoadWidgetFontData(fontname);
loadFont(data.data(), data.size());
try
{
if (sft_lmetrics(&sft, &textmetrics) < 0)
throw std::runtime_error("Could not get truetype font metrics");
}
catch (...)
{
sft_freefont(sft.font);
throw;
}
}
~CanvasFont()
{
sft_freefont(sft.font);
sft.font = nullptr;
}
CanvasGlyph* getGlyph(uint32_t utfchar)
{
auto& glyph = glyphs[utfchar];
if (glyph)
return glyph.get();
glyph = std::make_unique<CanvasGlyph>();
if (sft_lookup(&sft, utfchar, &glyph->id) < 0)
return glyph.get();
if (sft_gmetrics(&sft, glyph->id, &glyph->metrics) < 0)
return glyph.get();
glyph->metrics.advanceWidth /= 3.0;
glyph->metrics.leftSideBearing /= 3.0;
if (glyph->metrics.minWidth <= 0 || glyph->metrics.minHeight <= 0)
return glyph.get();
int w = (glyph->metrics.minWidth + 3) & ~3;
int h = glyph->metrics.minHeight;
int destwidth = (w + 2) / 3;
auto texture = std::make_shared<CanvasTexture>();
texture->Width = destwidth;
texture->Height = h;
texture->Data.resize(destwidth * h);
uint32_t* dest = (uint32_t*)texture->Data.data();
std::unique_ptr<uint8_t[]> grayscalebuffer(new uint8_t[w * h]);
uint8_t* grayscale = grayscalebuffer.get();
SFT_Image img = {};
img.width = w;
img.height = h;
img.pixels = grayscale;
if (sft_render(&sft, glyph->id, img) < 0)
return glyph.get();
for (int y = 0; y < h; y++)
{
uint8_t* sline = grayscale + y * w;
uint32_t* dline = dest + y * destwidth;
for (int x = 0; x < w; x += 3)
{
uint32_t values[5] =
{
x > 0 ? sline[x - 1] : 0U,
sline[x],
x + 1 < w ? sline[x + 1] : 0U,
x + 2 < w ? sline[x + 2] : 0U,
x + 3 < w ? sline[x + 3] : 0U
};
uint32_t red = (values[0] + values[1] + values[1] + values[2] + 2) >> 2;
uint32_t green = (values[1] + values[2] + values[2] + values[3] + 2) >> 2;
uint32_t blue = (values[2] + values[3] + values[3] + values[4] + 2) >> 2;
uint32_t alpha = (red | green | blue) ? 255 : 0;
*(dline++) = (alpha << 24) | (red << 16) | (green << 8) | blue;
}
}
glyph->u = 0.0;
glyph->v = 0.0;
glyph->uvwidth = destwidth;
glyph->uvheight = h;
glyph->texture = std::move(texture);
return glyph.get();
}
std::string fontname;
double height = 0.0;
SFT_LMetrics textmetrics = {};
std::unordered_map<uint32_t, std::unique_ptr<CanvasGlyph>> glyphs;
private:
void loadFont(const void* data, size_t size)
{
sft.xScale = height * 3;
sft.yScale = height;
sft.flags = SFT_DOWNWARD_Y;
sft.font = sft_loadmem(data, size);
}
SFT sft = {};
std::vector<uint8_t> data;
};
#endif
class BitmapCanvas : public Canvas
{
public:

View file

@ -1,16 +0,0 @@
ISC License
© 2019-2022 Thomas Oltmann and contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

File diff suppressed because it is too large Load diff

View file

@ -1,95 +0,0 @@
/* This file is part of libschrift.
*
* © 2019-2022 Thomas Oltmann and contributors
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
#ifndef SCHRIFT_H
#define SCHRIFT_H 1
#include <stddef.h> /* size_t */
#include <stdint.h> /* uint_fast32_t, uint_least32_t */
#ifdef __cplusplus
extern "C" {
#endif
#define SFT_DOWNWARD_Y 0x01
typedef struct SFT SFT;
typedef struct SFT_Font SFT_Font;
typedef uint_least32_t SFT_UChar; /* Guaranteed to be compatible with char32_t. */
typedef uint_fast32_t SFT_Glyph;
typedef struct SFT_LMetrics SFT_LMetrics;
typedef struct SFT_GMetrics SFT_GMetrics;
typedef struct SFT_Kerning SFT_Kerning;
typedef struct SFT_Image SFT_Image;
struct SFT
{
SFT_Font *font;
double xScale;
double yScale;
double xOffset;
double yOffset;
int flags;
};
struct SFT_LMetrics
{
double ascender;
double descender;
double lineGap;
};
struct SFT_GMetrics
{
double advanceWidth;
double leftSideBearing;
int yOffset;
int minWidth;
int minHeight;
};
struct SFT_Kerning
{
double xShift;
double yShift;
};
struct SFT_Image
{
void *pixels;
int width;
int height;
};
const char *sft_version(void);
SFT_Font *sft_loadmem (const void *mem, size_t size);
SFT_Font *sft_loadfile(const char *filename);
void sft_freefont(SFT_Font *font);
int sft_lmetrics(const SFT *sft, SFT_LMetrics *metrics);
int sft_lookup (const SFT *sft, SFT_UChar codepoint, SFT_Glyph *glyph);
int sft_gmetrics(const SFT *sft, SFT_Glyph glyph, SFT_GMetrics *metrics);
int sft_kerning (const SFT *sft, SFT_Glyph leftGlyph, SFT_Glyph rightGlyph,
SFT_Kerning *kerning);
int sft_render (const SFT *sft, SFT_Glyph glyph, SFT_Image image);
#ifdef __cplusplus
}
#endif
#endif