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