Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System ignores carrige return in text blocks in loaded CDX #1740

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions core/indigo-core/molecule/src/molecule_cdxml_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,51 +1220,56 @@ void MoleculeCdxmlLoader::_parseText(CDXElement elem, std::vector<std::pair<Vec3
for (auto text_style = elem.firstChildElement(); text_style.hasContent(); text_style = text_style.nextSiblingElement())
{
std::string text_element = text_style.name();
auto& ket_text_line = ket_text_lines.back();
if (text_element == "s")
{
std::string label_part = text_style.getText();
if (label_part == "+")
std::string style_text = text_style.getText();
if (style_text == "+")
{
_pluses.push_back(text_bbox.center());
return;
}

ket_text_line.text_styles.emplace_back();
auto& ket_text_style = ket_text_line.text_styles.back();
auto lines = split(style_text, '\n');
for (auto i = 0; i < lines.size(); ++i)
{
const auto& label_part = lines[i];
auto& ket_text_line = ket_text_lines.back();
ket_text_line.text_styles.emplace_back();
auto& ket_text_style = ket_text_line.text_styles.back();

auto initial_size = label_part.size();
label_part.erase(std::remove_if(label_part.begin(), label_part.end(), [](auto ch) { return (ch == '\n' || ch == '\r'); }), label_part.end());
if (initial_size > label_part.size()) // line break
ket_text_lines.emplace_back();
auto initial_size = label_part.size();

ket_text_style.offset = ket_text_line.text.size();
ket_text_style.size = label_part.size();
ket_text_line.text += label_part;
ket_text_style.offset = ket_text_line.text.size();
ket_text_style.size = label_part.size();
ket_text_line.text += label_part;

font_face = 0;
font_size = 0.0;
auto style = text_style.firstProperty();
applyDispatcher(style, style_dispatcher);
font_face = 0;
font_size = 0.0;
auto style = text_style.firstProperty();
applyDispatcher(style, style_dispatcher);

CDXMLFontStyle fs(font_face);
if (font_face == KCDXMLChemicalFontStyle)
{
// special case
}
else
{
if (fs.is_bold)
ket_text_style.styles.push_back(KETFontBoldStr);
if (fs.is_italic)
ket_text_style.styles.push_back(KETFontItalicStr);
if (fs.is_superscript)
ket_text_style.styles.push_back(KETFontSuperscriptStr);
if (fs.is_subscript)
ket_text_style.styles.push_back(KETFontSubscriptStr);
CDXMLFontStyle fs(font_face);
if (font_face == KCDXMLChemicalFontStyle)
{
// special case
}
else
{
if (fs.is_bold)
ket_text_style.styles.push_back(KETFontBoldStr);
if (fs.is_italic)
ket_text_style.styles.push_back(KETFontItalicStr);
if (fs.is_superscript)
ket_text_style.styles.push_back(KETFontSuperscriptStr);
if (fs.is_subscript)
ket_text_style.styles.push_back(KETFontSubscriptStr);
}
if (font_size > 0 && (int)font_size != KETDefaultFontSize)
ket_text_style.styles.push_back(std::string(KETFontCustomSizeStr) + "_" + std::to_string((int)ceil(font_size)) + "px");

if (i < lines.size() - 1)
ket_text_lines.emplace_back();
}
if (font_size > 0 && (int)font_size != KETDefaultFontSize)
ket_text_style.styles.push_back(std::string(KETFontCustomSizeStr) + "_" + std::to_string((int)ceil(font_size)) + "px");
}
}

Expand Down
Loading