diff --git a/lib/Epub/Epub/Section.cpp b/lib/Epub/Epub/Section.cpp index d2404328..c90a3a6e 100644 --- a/lib/Epub/Epub/Section.cpp +++ b/lib/Epub/Epub/Section.cpp @@ -178,8 +178,8 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c ChapterHtmlSlimParser visitor( tmpHtmlPath, renderer, fontId, lineCompression, extraParagraphSpacing, paragraphAlignment, viewportWidth, viewportHeight, - [this, &lut](std::unique_ptr page) { lut.emplace_back(this->onPageComplete(std::move(page))); }, - progressFn, epub->getCssParser()); + [this, &lut](std::unique_ptr page) { lut.emplace_back(this->onPageComplete(std::move(page))); }, progressFn, + epub->getCssParser()); success = visitor.parseAndBuildPages(); SdMan.remove(tmpHtmlPath.c_str()); diff --git a/lib/Epub/Epub/blocks/TextBlock.h b/lib/Epub/Epub/blocks/TextBlock.h index 68f5c7f8..e7993fe8 100644 --- a/lib/Epub/Epub/blocks/TextBlock.h +++ b/lib/Epub/Epub/blocks/TextBlock.h @@ -30,8 +30,7 @@ class TextBlock final : public Block { public: explicit TextBlock(std::list words, std::list word_xpos, std::list word_styles, const Style style, - const BlockStyle& blockStyle = BlockStyle(), - std::list word_underlines = std::list()) + const BlockStyle& blockStyle = BlockStyle(), std::list word_underlines = std::list()) : words(std::move(words)), wordXpos(std::move(word_xpos)), wordStyles(std::move(word_styles)), diff --git a/lib/Epub/Epub/css/CssParser.cpp b/lib/Epub/Epub/css/CssParser.cpp index 7ef3f839..b62f0b57 100644 --- a/lib/Epub/Epub/css/CssParser.cpp +++ b/lib/Epub/Epub/css/CssParser.cpp @@ -14,9 +14,7 @@ constexpr size_t READ_BUFFER_SIZE = 512; constexpr size_t MAX_CSS_SIZE = 64 * 1024; // Check if character is CSS whitespace -bool isCssWhitespace(const char c) { - return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f'; -} +bool isCssWhitespace(const char c) { return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f'; } // Read entire file into string (with size limit) std::string readFileContent(FsFile& file) { @@ -88,8 +86,7 @@ size_t skipAtRule(const std::string& css, const size_t start) { // Extract next rule from CSS content // Returns true if a rule was found, with selector and body filled -bool extractNextRule(const std::string& css, size_t& pos, - std::string& selector, std::string& body) { +bool extractNextRule(const std::string& css, size_t& pos, std::string& selector, std::string& body) { selector.clear(); body.clear(); @@ -126,8 +123,10 @@ bool extractNextRule(const std::string& css, size_t& pos, size_t bodyEnd = bodyStart; while (bodyEnd < css.size() && depth > 0) { - if (css[bodyEnd] == '{') ++depth; - else if (css[bodyEnd] == '}') --depth; + if (css[bodyEnd] == '{') + ++depth; + else if (css[bodyEnd] == '}') + --depth; ++bodyEnd; } @@ -402,8 +401,7 @@ CssStyle CssParser::parseDeclarations(const std::string& declBlock) { // Rule processing -void CssParser::processRuleBlock(const std::string& selectorGroup, - const std::string& declarations) { +void CssParser::processRuleBlock(const std::string& selectorGroup, const std::string& declarations) { const CssStyle style = parseDeclarations(declarations); // Only store if any properties were set @@ -458,8 +456,7 @@ bool CssParser::loadFromStream(FsFile& source) { // Style resolution -CssStyle CssParser::resolveStyle(const std::string& tagName, - const std::string& classAttr) const { +CssStyle CssParser::resolveStyle(const std::string& tagName, const std::string& classAttr) const { CssStyle result; const std::string tag = normalized(tagName); @@ -498,6 +495,4 @@ CssStyle CssParser::resolveStyle(const std::string& tagName, // Inline style parsing (static - doesn't need rule database) -CssStyle CssParser::parseInlineStyle(const std::string& styleValue) { - return parseDeclarations(styleValue); -} +CssStyle CssParser::parseInlineStyle(const std::string& styleValue) { return parseDeclarations(styleValue); } diff --git a/lib/Epub/Epub/css/CssParser.h b/lib/Epub/Epub/css/CssParser.h index a10e9027..a1802369 100644 --- a/lib/Epub/Epub/css/CssParser.h +++ b/lib/Epub/Epub/css/CssParser.h @@ -52,8 +52,7 @@ class CssParser { * @param classAttr The class attribute value (may contain multiple space-separated classes) * @return Combined style with all applicable rules merged */ - [[nodiscard]] CssStyle resolveStyle(const std::string& tagName, - const std::string& classAttr) const; + [[nodiscard]] CssStyle resolveStyle(const std::string& tagName, const std::string& classAttr) const; /** * Parse an inline style attribute string. diff --git a/lib/Epub/Epub/css/CssStyle.h b/lib/Epub/Epub/css/CssStyle.h index ea6a9d3b..83331617 100644 --- a/lib/Epub/Epub/css/CssStyle.h +++ b/lib/Epub/Epub/css/CssStyle.h @@ -3,31 +3,16 @@ #include // Text alignment options matching CSS text-align property -enum class TextAlign : uint8_t { - None = 0, - Left = 1, - Right = 2, - Center = 3, - Justify = 4 -}; +enum class TextAlign : uint8_t { None = 0, Left = 1, Right = 2, Center = 3, Justify = 4 }; // Font style options matching CSS font-style property -enum class CssFontStyle : uint8_t { - Normal = 0, - Italic = 1 -}; +enum class CssFontStyle : uint8_t { Normal = 0, Italic = 1 }; // Font weight options - CSS supports 100-900, we simplify to normal/bold -enum class CssFontWeight : uint8_t { - Normal = 0, - Bold = 1 -}; +enum class CssFontWeight : uint8_t { Normal = 0, Bold = 1 }; // Text decoration options -enum class CssTextDecoration : uint8_t { - None = 0, - Underline = 1 -}; +enum class CssTextDecoration : uint8_t { None = 0, Underline = 1 }; // Bitmask for tracking which properties have been explicitly set struct CssPropertyFlags { @@ -42,13 +27,21 @@ struct CssPropertyFlags { uint16_t paddingBottom : 1; uint16_t reserved : 7; - CssPropertyFlags() : alignment(0), fontStyle(0), fontWeight(0), decoration(0), - indent(0), marginTop(0), marginBottom(0), - paddingTop(0), paddingBottom(0), reserved(0) {} + CssPropertyFlags() + : alignment(0), + fontStyle(0), + fontWeight(0), + decoration(0), + indent(0), + marginTop(0), + marginBottom(0), + paddingTop(0), + paddingBottom(0), + reserved(0) {} [[nodiscard]] bool anySet() const { - return alignment || fontStyle || fontWeight || decoration || - indent || marginTop || marginBottom || paddingTop || paddingBottom; + return alignment || fontStyle || fontWeight || decoration || indent || marginTop || marginBottom || paddingTop || + paddingBottom; } void clearAll() { @@ -65,13 +58,13 @@ struct CssStyle { CssFontWeight fontWeight = CssFontWeight::Normal; CssTextDecoration decoration = CssTextDecoration::None; - float indentPixels = 0.0f; // First-line indent in pixels - int8_t marginTop = 0; // Vertical spacing before block (in lines, 0-2) - int8_t marginBottom = 0; // Vertical spacing after block (in lines, 0-2) - int8_t paddingTop = 0; // Padding before (in lines, 0-2) - int8_t paddingBottom = 0; // Padding after (in lines, 0-2) + float indentPixels = 0.0f; // First-line indent in pixels + int8_t marginTop = 0; // Vertical spacing before block (in lines, 0-2) + int8_t marginBottom = 0; // Vertical spacing after block (in lines, 0-2) + int8_t paddingTop = 0; // Padding before (in lines, 0-2) + int8_t paddingBottom = 0; // Padding after (in lines, 0-2) - CssPropertyFlags defined; // Tracks which properties were explicitly set + CssPropertyFlags defined; // Tracks which properties were explicitly set // Apply properties from another style, only overwriting if the other style // has that property explicitly defined diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index 0143a56e..923ed68f 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -59,7 +59,8 @@ void ChapterHtmlSlimParser::updateEffectiveInlineStyle() { // Start with block-level styles effectiveBold = currentBlockStyle.hasFontWeight() && currentBlockStyle.fontWeight == CssFontWeight::Bold; effectiveItalic = currentBlockStyle.hasFontStyle() && currentBlockStyle.fontStyle == CssFontStyle::Italic; - effectiveUnderline = currentBlockStyle.hasTextDecoration() && currentBlockStyle.decoration == CssTextDecoration::Underline; + effectiveUnderline = + currentBlockStyle.hasTextDecoration() && currentBlockStyle.decoration == CssTextDecoration::Underline; // Apply inline style stack in order for (const auto& entry : inlineStyleStack) { @@ -90,9 +91,7 @@ void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::Style style, cons currentTextBlock.reset(new ParsedText(style, extraParagraphSpacing, blockStyle)); } -void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::Style style) { - startNewTextBlock(style, BlockStyle{}); -} +void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::Style style) { startNewTextBlock(style, BlockStyle{}); } void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* name, const XML_Char** atts) { auto* self = static_cast(userData); @@ -174,8 +173,7 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* } // Determine if this is a block element - bool isBlockElement = - matches(name, HEADER_TAGS, NUM_HEADER_TAGS) || matches(name, BLOCK_TAGS, NUM_BLOCK_TAGS); + bool isBlockElement = matches(name, HEADER_TAGS, NUM_HEADER_TAGS) || matches(name, BLOCK_TAGS, NUM_BLOCK_TAGS); // Compute CSS style for this element CssStyle cssStyle; @@ -415,8 +413,8 @@ void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* n // Check if any style state will change after we decrement depth // If so, we MUST flush the partWordBuffer with the CURRENT style first // Note: depth hasn't been decremented yet, so we check against (depth - 1) - const bool willPopStyleStack = !self->inlineStyleStack.empty() && - self->inlineStyleStack.back().depth == self->depth - 1; + const bool willPopStyleStack = + !self->inlineStyleStack.empty() && self->inlineStyleStack.back().depth == self->depth - 1; const bool willClearBold = self->boldUntilDepth == self->depth - 1; const bool willClearItalic = self->italicUntilDepth == self->depth - 1; const bool willClearUnderline = self->underlineUntilDepth == self->depth - 1; @@ -426,10 +424,10 @@ void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* n // Flush buffer with current style BEFORE any style changes if (self->partWordBufferIndex > 0) { // Flush if style will change OR if we're closing a block/structural element - const bool shouldFlush = styleWillChange || - matches(name, BLOCK_TAGS, NUM_BLOCK_TAGS) || matches(name, HEADER_TAGS, NUM_HEADER_TAGS) || - matches(name, BOLD_TAGS, NUM_BOLD_TAGS) || matches(name, ITALIC_TAGS, NUM_ITALIC_TAGS) || - matches(name, UNDERLINE_TAGS, NUM_UNDERLINE_TAGS) || self->depth == 1; + const bool shouldFlush = styleWillChange || matches(name, BLOCK_TAGS, NUM_BLOCK_TAGS) || + matches(name, HEADER_TAGS, NUM_HEADER_TAGS) || matches(name, BOLD_TAGS, NUM_BOLD_TAGS) || + matches(name, ITALIC_TAGS, NUM_ITALIC_TAGS) || + matches(name, UNDERLINE_TAGS, NUM_UNDERLINE_TAGS) || self->depth == 1; if (shouldFlush) { // Use combined depth-based and CSS-based style