Review comments
This commit is contained in:
@@ -18,17 +18,22 @@ void TextBlock::render(const GfxRenderer& renderer, const int fontId, const int
|
|||||||
renderer.drawText(fontId, wordX, y, words[i].c_str(), true, currentStyle);
|
renderer.drawText(fontId, wordX, y, words[i].c_str(), true, currentStyle);
|
||||||
|
|
||||||
const std::string& w = words[i];
|
const std::string& w = words[i];
|
||||||
const int fullWordWidth = renderer.getTextWidth(fontId, w.c_str(), currentStyle);
|
|
||||||
int startX = wordX;
|
|
||||||
int lineWidth = fullWordWidth;
|
|
||||||
const bool hasEmSpacePrefix = w.size() >= 3 && static_cast<uint8_t>(w[0]) == 0xE2 &&
|
const bool hasEmSpacePrefix = w.size() >= 3 && static_cast<uint8_t>(w[0]) == 0xE2 &&
|
||||||
static_cast<uint8_t>(w[1]) == 0x80 && static_cast<uint8_t>(w[2]) == 0x83;
|
static_cast<uint8_t>(w[1]) == 0x80 && static_cast<uint8_t>(w[2]) == 0x83;
|
||||||
if (hasEmSpacePrefix) {
|
const bool hasDecoration = (currentStyle & (EpdFontFamily::UNDERLINE | EpdFontFamily::STRIKETHROUGH)) != 0;
|
||||||
const char* visiblePtr = w.c_str() + 3;
|
int startX = wordX;
|
||||||
const int prefixWidth = renderer.getTextAdvanceX(fontId, "\xe2\x80\x83", currentStyle);
|
int lineWidth = 0;
|
||||||
const int visibleWidth = renderer.getTextWidth(fontId, visiblePtr, currentStyle);
|
|
||||||
startX = wordX + prefixWidth;
|
if (hasEmSpacePrefix || hasDecoration) {
|
||||||
lineWidth = visibleWidth;
|
const int fullWordWidth = renderer.getTextWidth(fontId, w.c_str(), currentStyle);
|
||||||
|
lineWidth = fullWordWidth;
|
||||||
|
if (hasEmSpacePrefix) {
|
||||||
|
const char* visiblePtr = w.c_str() + 3;
|
||||||
|
const int prefixWidth = renderer.getTextAdvanceX(fontId, "\xe2\x80\x83", currentStyle);
|
||||||
|
const int visibleWidth = renderer.getTextWidth(fontId, visiblePtr, currentStyle);
|
||||||
|
startX = wordX + prefixWidth;
|
||||||
|
lineWidth = visibleWidth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((currentStyle & EpdFontFamily::UNDERLINE) != 0) {
|
if ((currentStyle & EpdFontFamily::UNDERLINE) != 0) {
|
||||||
|
|||||||
@@ -894,6 +894,19 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
|
|||||||
entry.hasStrikethrough = true;
|
entry.hasStrikethrough = true;
|
||||||
entry.strikethrough = true;
|
entry.strikethrough = true;
|
||||||
}
|
}
|
||||||
|
if (cssStyle.hasTextDecoration()) {
|
||||||
|
const uint8_t dec = static_cast<uint8_t>(cssStyle.textDecoration);
|
||||||
|
if (dec & static_cast<uint8_t>(CssTextDecoration::Underline)) {
|
||||||
|
entry.hasUnderline = true;
|
||||||
|
entry.underline = true;
|
||||||
|
self->underlineUntilDepth = std::min(self->underlineUntilDepth, self->depth);
|
||||||
|
}
|
||||||
|
if (dec & static_cast<uint8_t>(CssTextDecoration::LineThrough)) {
|
||||||
|
entry.hasStrikethrough = true;
|
||||||
|
entry.strikethrough = true;
|
||||||
|
self->strikethroughUntilDepth = std::min(self->strikethroughUntilDepth, self->depth);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (cssStyle.hasFontWeight()) {
|
if (cssStyle.hasFontWeight()) {
|
||||||
entry.hasBold = true;
|
entry.hasBold = true;
|
||||||
entry.bold = cssStyle.fontWeight == CssFontWeight::Bold;
|
entry.bold = cssStyle.fontWeight == CssFontWeight::Bold;
|
||||||
|
|||||||
+4
-6
@@ -93,7 +93,7 @@ std::vector<Span> parseInline(const std::string& text) {
|
|||||||
// Escaped character
|
// Escaped character
|
||||||
if (c == '\\' && i + 1 < text.size()) {
|
if (c == '\\' && i + 1 < text.size()) {
|
||||||
char next = text[i + 1];
|
char next = text[i + 1];
|
||||||
if (next == '*' || next == '_' || next == '`' || next == '[' || next == '!' || next == '\\') {
|
if (next == '*' || next == '_' || next == '`' || next == '[' || next == '!' || next == '~' || next == '\\') {
|
||||||
current += next;
|
current += next;
|
||||||
i += 2;
|
i += 2;
|
||||||
continue;
|
continue;
|
||||||
@@ -329,12 +329,10 @@ ParsedLine parseLine(const std::string& rawLine, bool inCodeBlock) {
|
|||||||
result.blockType = BlockType::Header3;
|
result.blockType = BlockType::Header3;
|
||||||
|
|
||||||
result.spans = parseInline(content);
|
result.spans = parseInline(content);
|
||||||
// Force bold on all header spans
|
// Force bold on all header spans while preserving any existing decoration bits.
|
||||||
for (auto& span : result.spans) {
|
for (auto& span : result.spans) {
|
||||||
if (span.style == EpdFontFamily::REGULAR)
|
span.style = static_cast<EpdFontFamily::Style>(static_cast<uint8_t>(span.style) |
|
||||||
span.style = EpdFontFamily::BOLD;
|
static_cast<uint8_t>(EpdFontFamily::BOLD));
|
||||||
else if (span.style == EpdFontFamily::ITALIC)
|
|
||||||
span.style = EpdFontFamily::BOLD_ITALIC;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ static int testsFailed = 0;
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ASSERT_TRUE(cond) \
|
#define ASSERT_TRUE(cond) \
|
||||||
do { \
|
do { \
|
||||||
if (!(cond)) { \
|
if (!(cond)) { \
|
||||||
fprintf(stderr, " FAIL: %s:%d: %s is false\n", __FILE__, __LINE__, #cond); \
|
fprintf(stderr, " FAIL: %s:%d: %s is false\n", __FILE__, __LINE__, #cond); \
|
||||||
testsFailed++; \
|
testsFailed++; \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define PASS() testsPassed++
|
#define PASS() testsPassed++
|
||||||
@@ -42,6 +42,14 @@ void testInlineUnderlineLineThrough() {
|
|||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testInlineLineThroughUnderlineOrderInsensitive() {
|
||||||
|
printf("testInlineLineThroughUnderlineOrderInsensitive...\n");
|
||||||
|
const CssStyle style = CssParser::parseInlineStyle("text-decoration: line-through underline");
|
||||||
|
ASSERT_TRUE(style.hasTextDecoration());
|
||||||
|
ASSERT_EQ(style.textDecoration, CssTextDecoration::UnderlineLineThrough);
|
||||||
|
PASS();
|
||||||
|
}
|
||||||
|
|
||||||
void testInlineTextDecorationNormalization() {
|
void testInlineTextDecorationNormalization() {
|
||||||
printf("testInlineTextDecorationNormalization...\n");
|
printf("testInlineTextDecorationNormalization...\n");
|
||||||
const CssStyle style = CssParser::parseInlineStyle("TEXT-DECORATION : LINE-THROUGH ;");
|
const CssStyle style = CssParser::parseInlineStyle("TEXT-DECORATION : LINE-THROUGH ;");
|
||||||
@@ -55,6 +63,7 @@ int main() {
|
|||||||
|
|
||||||
testInlineLineThrough();
|
testInlineLineThrough();
|
||||||
testInlineUnderlineLineThrough();
|
testInlineUnderlineLineThrough();
|
||||||
|
testInlineLineThroughUnderlineOrderInsensitive();
|
||||||
testInlineTextDecorationNormalization();
|
testInlineTextDecorationNormalization();
|
||||||
|
|
||||||
printf("\n=== Results: %d passed, %d failed ===\n", testsPassed, testsFailed);
|
printf("\n=== Results: %d passed, %d failed ===\n", testsPassed, testsFailed);
|
||||||
|
|||||||
@@ -78,6 +78,15 @@ void testStrikethroughWorks() {
|
|||||||
PASS();
|
PASS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testEscapedTildeDoesNotToggleStrikethrough() {
|
||||||
|
printf("testEscapedTildeDoesNotToggleStrikethrough...\n");
|
||||||
|
auto spans = MdParser::parseInline("foo \\~~bar~~ baz");
|
||||||
|
ASSERT_EQ(flattenText(spans), "foo ~~bar~~ baz");
|
||||||
|
ASSERT_EQ(spans.size(), 1);
|
||||||
|
ASSERT_EQ(spans[0].style, EpdFontFamily::REGULAR);
|
||||||
|
PASS();
|
||||||
|
}
|
||||||
|
|
||||||
void testUnderscoreBoldWorks() {
|
void testUnderscoreBoldWorks() {
|
||||||
printf("testUnderscoreBoldWorks...\n");
|
printf("testUnderscoreBoldWorks...\n");
|
||||||
auto spans = MdParser::parseInline("foo __bar__ baz");
|
auto spans = MdParser::parseInline("foo __bar__ baz");
|
||||||
@@ -116,6 +125,7 @@ int main() {
|
|||||||
testAsteriskEmphasisStillWorks();
|
testAsteriskEmphasisStillWorks();
|
||||||
testStrikethroughWorks();
|
testStrikethroughWorks();
|
||||||
testUnderscoreBoldWorks();
|
testUnderscoreBoldWorks();
|
||||||
|
testEscapedTildeDoesNotToggleStrikethrough();
|
||||||
testNestedUnorderedListIndentLevel();
|
testNestedUnorderedListIndentLevel();
|
||||||
testNestedOrderedListIndentLevel();
|
testNestedOrderedListIndentLevel();
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,16 @@ BINARY="$BUILD_DIR/CssParserTest"
|
|||||||
PLATFORMIO_DIR="${PLATFORMIO_CORE_DIR:-$HOME/.platformio}"
|
PLATFORMIO_DIR="${PLATFORMIO_CORE_DIR:-$HOME/.platformio}"
|
||||||
ARDUINO_FRAMEWORK_DIR="$PLATFORMIO_DIR/packages/framework-arduinoespressif32"
|
ARDUINO_FRAMEWORK_DIR="$PLATFORMIO_DIR/packages/framework-arduinoespressif32"
|
||||||
|
|
||||||
|
if [ ! -d "$PLATFORMIO_DIR" ]; then
|
||||||
|
echo "ERROR: PLATFORMIO_DIR does not exist: $PLATFORMIO_DIR" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$ARDUINO_FRAMEWORK_DIR" ]; then
|
||||||
|
echo "ERROR: ARDUINO_FRAMEWORK_DIR does not exist: $ARDUINO_FRAMEWORK_DIR" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
mkdir -p "$BUILD_DIR"
|
mkdir -p "$BUILD_DIR"
|
||||||
|
|
||||||
SOURCES=(
|
SOURCES=(
|
||||||
|
|||||||
Reference in New Issue
Block a user