mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[reader] Fix bug in Latex handling
This commit is contained in:
@@ -12,41 +12,7 @@ TexParser::TexParser(const char * text, const char * endOfText) :
|
||||
}
|
||||
|
||||
Layout TexParser::getLayout() {
|
||||
HorizontalLayout layout = HorizontalLayout::Builder();
|
||||
const char * start = m_text;
|
||||
|
||||
while (m_text < m_endOfText) {
|
||||
if (*m_text == '\\') {
|
||||
if (start != m_text) {
|
||||
layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false);
|
||||
}
|
||||
m_text ++;
|
||||
layout.addOrMergeChildAtIndex(popCommand(), layout.numberOfChildren(), false);
|
||||
start = m_text;
|
||||
}
|
||||
else if (*m_text == " ") {
|
||||
if (start != m_text) {
|
||||
layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false);
|
||||
}
|
||||
m_text ++;
|
||||
start = m_text;
|
||||
}
|
||||
else if (*m_text == "^") {
|
||||
if (start != m_text) {
|
||||
layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false);
|
||||
}
|
||||
m_text ++;
|
||||
layout.addOrMergeChildAtIndex(popCommand(), layout.numberOfChildren(), false);
|
||||
start = m_text;
|
||||
}
|
||||
else {
|
||||
m_text ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (start != m_text) {
|
||||
layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false);
|
||||
}
|
||||
Layout layout = popText(0);
|
||||
|
||||
if (m_hasError) {
|
||||
return CodePointLayout::Builder(CodePoint(0xFFD));
|
||||
@@ -55,12 +21,12 @@ Layout TexParser::getLayout() {
|
||||
return layout;
|
||||
}
|
||||
|
||||
Layout TexParser::popBlock() {
|
||||
Layout TexParser::popBlock(char block) {
|
||||
while (*m_text == ' ') {
|
||||
m_text ++;
|
||||
}
|
||||
|
||||
if (*m_text == '{') {
|
||||
if (*m_text == block) {
|
||||
m_text ++;
|
||||
return popText('}');
|
||||
}
|
||||
@@ -80,28 +46,48 @@ Layout TexParser::popBlock() {
|
||||
}
|
||||
|
||||
Layout TexParser::popText(char stop) {
|
||||
if (*m_text == '\\') {
|
||||
m_text ++;
|
||||
return popCommand();
|
||||
}
|
||||
|
||||
HorizontalLayout layout = HorizontalLayout::Builder();
|
||||
const char * start = m_text;
|
||||
|
||||
while (m_text < m_endOfText) {
|
||||
if (*m_text == '\\') {
|
||||
layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false);
|
||||
m_text ++;
|
||||
layout.addOrMergeChildAtIndex(popCommand(), layout.numberOfChildren(), false);
|
||||
start = m_text;
|
||||
while (m_text < m_endOfText && *m_text != stop) {
|
||||
switch (*m_text) {
|
||||
case '\\':
|
||||
if (start != m_text) {
|
||||
layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false);
|
||||
}
|
||||
m_text ++;
|
||||
layout.addOrMergeChildAtIndex(popCommand(), 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 ++;
|
||||
start = m_text;
|
||||
break;
|
||||
case '^':
|
||||
if (start != m_text) {
|
||||
layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false);
|
||||
}
|
||||
m_text ++;
|
||||
layout.addOrMergeChildAtIndex(popCommand(), layout.numberOfChildren(), false);
|
||||
start = m_text;
|
||||
break;
|
||||
default:
|
||||
m_text ++;
|
||||
}
|
||||
|
||||
m_text ++;
|
||||
}
|
||||
|
||||
if (start != m_text) {
|
||||
layout.addOrMergeChildAtIndex(LayoutHelper::String(start, m_text - start), layout.numberOfChildren(), false);
|
||||
}
|
||||
if (layout.numberOfChildren() == 1) {
|
||||
layout.squashUnaryHierarchyInPlace();
|
||||
}
|
||||
|
||||
m_text ++;
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@@ -116,8 +102,8 @@ Layout TexParser::popCommand() {
|
||||
}
|
||||
|
||||
Layout TexParser::popFracCommand() {
|
||||
Layout firstBlock = popBlock();
|
||||
Layout secondBlock = popBlock();
|
||||
Layout firstBlock = popBlock('{');
|
||||
Layout secondBlock = popBlock('{');
|
||||
return FractionLayout::Builder(firstBlock, secondBlock);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user