This commit is contained in:
Jonas Diemer 2025-12-15 19:21:57 +00:00 committed by GitHub
commit 7b638376c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 4 deletions

View File

@ -122,7 +122,13 @@ void ParsedText::layoutAndExtractLines(const GfxRenderer& renderer, const int fo
}
// Calculate spacing
const int spareSpace = pageWidth - lineWordWidthSum;
int spareSpace = pageWidth - lineWordWidthSum;
// width of 1em to indent first line of paragraph
const int indentWidth = 1 * renderer.getTextWidth(fontId, "m", REGULAR);
if (!extraParagraphSpacing && wordWidthIndex ==0) {
spareSpace -= indentWidth;
}
int spacing = spaceWidth;
const bool isLastLine = lineBreak == totalWordCount;
@ -132,6 +138,9 @@ void ParsedText::layoutAndExtractLines(const GfxRenderer& renderer, const int fo
// Calculate initial x position
uint16_t xpos = 0;
if (!extraParagraphSpacing && wordWidthIndex ==0) {
xpos = indentWidth;
}
if (style == TextBlock::RIGHT_ALIGN) {
xpos = spareSpace - (lineWordCount - 1) * spaceWidth;
} else if (style == TextBlock::CENTER_ALIGN) {

View File

@ -16,9 +16,11 @@ class ParsedText {
std::list<std::string> words;
std::list<EpdFontStyle> wordStyles;
TextBlock::BLOCK_STYLE style;
bool extraParagraphSpacing;
public:
explicit ParsedText(const TextBlock::BLOCK_STYLE style) : style(style) {}
explicit ParsedText(const TextBlock::BLOCK_STYLE style, const bool extraParagraphSpacing)
: style(style), extraParagraphSpacing(extraParagraphSpacing) {}
~ParsedText() = default;
void addWord(std::string word, EpdFontStyle fontStyle);

View File

@ -25,7 +25,7 @@ constexpr int NUM_IMAGE_TAGS = sizeof(IMAGE_TAGS) / sizeof(IMAGE_TAGS[0]);
const char* SKIP_TAGS[] = {"head", "table"};
constexpr int NUM_SKIP_TAGS = sizeof(SKIP_TAGS) / sizeof(SKIP_TAGS[0]);
bool isWhitespace(const char c) { return c == ' ' || c == '\r' || c == '\n'; }
bool isWhitespace(const char c) { return c == ' ' || c == '\r' || c == '\n' || c == '\t'; }
// given the start and end of a tag, check to see if it matches a known tag
bool matches(const char* tag_name, const char* possible_tags[], const int possible_tag_count) {
@ -48,7 +48,7 @@ void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::BLOCK_STYLE style
makePages();
}
currentTextBlock.reset(new ParsedText(style));
currentTextBlock.reset(new ParsedText(style, extraParagraphSpacing));
}
void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* name, const XML_Char** atts) {