## Summary * **What is the goal of this PR?** Support for `<sup>` and `<sub>` tags. ## Additional Context This isn't my work, but @jpirnay 's (missing you here, man!). I migrated his work from https://github.com/jpirnay/crosspoint-reader/commit/bcd8c32cf26447ccc792cfedd2fdbfce4fee5210 with some micro-optimizations. Screenshots: [Subscript-and-Superscript-Tests_ch2_p1_10pct_55632.bmp](https://github.com/user-attachments/files/28196936/Subscript-and-Superscript-Tests_ch2_p1_10pct_55632.bmp) [Subscript-and-Superscript-Tests_ch3_p1_21pct_77473.bmp](https://github.com/user-attachments/files/28196937/Subscript-and-Superscript-Tests_ch3_p1_21pct_77473.bmp) --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**< YES >**_ --------- Co-authored-by: jpirnay <jens@pirnay.com> Co-authored-by: Julia <julia@uxj.io>
39 lines
1.7 KiB
C++
39 lines
1.7 KiB
C++
#pragma once
|
|
#include "EpdFont.h"
|
|
|
|
class EpdFontFamily {
|
|
public:
|
|
// Bitmask of text style flags carried per-word through layout and serialized in page cache.
|
|
// Bits 0-1 select the font variant (BOLD/ITALIC); bits 2-5 are decoration/positioning overlays
|
|
// applied at render time without changing the underlying font. getFont() ignores all bits
|
|
// above bit 1 so decorations compose freely with bold/italic (e.g. BOLD | UNDERLINE | SUP).
|
|
enum Style : uint8_t {
|
|
REGULAR = 0,
|
|
BOLD = 1,
|
|
ITALIC = 2,
|
|
BOLD_ITALIC = 3,
|
|
UNDERLINE = 4, // drawn as a line below baseline by TextBlock::render()
|
|
STRIKETHROUGH = 8, // drawn as a line through midline by TextBlock::render()
|
|
SUP = 16, // superscript: glyph scaled 50%, raised ~40% of ascender
|
|
SUB = 32, // subscript: glyph scaled 50%, lowered ~25% of ascender
|
|
};
|
|
|
|
explicit EpdFontFamily(const EpdFont* regular, const EpdFont* bold = nullptr, const EpdFont* italic = nullptr,
|
|
const EpdFont* boldItalic = nullptr)
|
|
: regular(regular), bold(bold), italic(italic), boldItalic(boldItalic) {}
|
|
~EpdFontFamily() = default;
|
|
void getTextDimensions(const char* string, int* w, int* h, Style style = REGULAR) const;
|
|
const EpdFontData* getData(Style style = REGULAR) const;
|
|
const EpdGlyph* getGlyph(uint32_t cp, Style style = REGULAR) const;
|
|
int8_t getKerning(uint32_t leftCp, uint32_t rightCp, Style style = REGULAR) const;
|
|
uint32_t applyLigatures(uint32_t cp, const char*& text, Style style = REGULAR) const;
|
|
|
|
private:
|
|
const EpdFont* regular;
|
|
const EpdFont* bold;
|
|
const EpdFont* italic;
|
|
const EpdFont* boldItalic;
|
|
|
|
const EpdFont* getFont(Style style) const;
|
|
};
|