From 5c9bccdd99dcc7b9d0da60055a6cb6a1e9024573 Mon Sep 17 00:00:00 2001 From: Laury Date: Sat, 23 Oct 2021 00:21:28 +0200 Subject: [PATCH] [reader] Continuation of Latex parser --- apps/reader/tex_parser.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/reader/tex_parser.cpp b/apps/reader/tex_parser.cpp index 5cd229ace..8fe531352 100644 --- a/apps/reader/tex_parser.cpp +++ b/apps/reader/tex_parser.cpp @@ -21,12 +21,12 @@ Layout TexParser::getLayout() { return layout; } -Layout TexParser::popBlock(char block) { +Layout TexParser::popBlock() { while (*m_text == ' ') { m_text ++; } - if (*m_text == block) { + if (*m_text == '{') { m_text ++; return popText('}'); } @@ -71,7 +71,15 @@ Layout TexParser::popText(char stop) { layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false); } m_text ++; - layout.addOrMergeChildAtIndex(popCommand(), layout.numberOfChildren(), false); + layout.addOrMergeChildAtIndex(VerticalOffsetLayout::Builder(popBlock(), VerticalOffsetLayoutNode::Position::Superscript), layout.numberOfChildren(), false); + start = m_text; + break; + case '_': + if (start != m_text) { + layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false); + } + m_text ++; + layout.addOrMergeChildAtIndex(VerticalOffsetLayout::Builder(popBlock(), VerticalOffsetLayoutNode::Position::Subscript), layout.numberOfChildren(), false); start = m_text; break; default: @@ -82,12 +90,13 @@ Layout TexParser::popText(char stop) { if (start != m_text) { layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false); } - if (layout.numberOfChildren() == 1) { - layout.squashUnaryHierarchyInPlace(); - } - + m_text ++; + if (layout.numberOfChildren() == 1) { + return layout.squashUnaryHierarchyInPlace(); + } + return layout; } @@ -102,9 +111,7 @@ Layout TexParser::popCommand() { } Layout TexParser::popFracCommand() { - Layout firstBlock = popBlock('{'); - Layout secondBlock = popBlock('{'); - return FractionLayout::Builder(firstBlock, secondBlock); + return FractionLayout::Builder(popBlock(), popBlock()); } }