mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
XHTML/DocBook: merge code duplicates for horizontal alignment.
This commit is contained in:
parent
c7896cf922
commit
ec01616247
@ -3639,6 +3639,33 @@ std::string Tabular::getVAlignAsXmlAttribute(idx_type cell) const
|
||||
}
|
||||
|
||||
|
||||
std::string Tabular::getHAlignAsXmlAttribute(idx_type cell, bool is_xhtml) const
|
||||
{
|
||||
// TODO: the Boolean flag isn't really clean; switch to an enum at some point.
|
||||
switch (getAlignment(cell)) {
|
||||
case LYX_ALIGN_LEFT:
|
||||
return "align='left'";
|
||||
case LYX_ALIGN_RIGHT:
|
||||
return "align='right'";
|
||||
|
||||
default:
|
||||
// HTML only supports left, right, and center.
|
||||
if (is_xhtml)
|
||||
return "align='center'";
|
||||
|
||||
// DocBook also has justify and decimal.
|
||||
if (getAlignment(cell) == LYX_ALIGN_BLOCK) {
|
||||
return "align='justify'";
|
||||
} else if (getAlignment(cell) == LYX_ALIGN_DECIMAL) {
|
||||
Language const *tlang = buffer().paragraphs().front().getParLanguage(buffer().params());
|
||||
return "align='char' char='" + to_utf8(tlang->decimalSeparator()) + "'";
|
||||
} else {
|
||||
return "align='center'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Tabular::docbookRowAsHTML(XMLStream & xs, row_type row,
|
||||
OutputParams const & runparams, bool header) const
|
||||
{
|
||||
@ -3659,27 +3686,7 @@ void Tabular::docbookRowAsHTML(XMLStream & xs, row_type row,
|
||||
attr << "style=\"width: " << hwidth << ";\" ";
|
||||
}
|
||||
|
||||
attr << "align='";
|
||||
switch (getAlignment(cell)) {
|
||||
case LYX_ALIGN_BLOCK:
|
||||
attr << "justify";
|
||||
break;
|
||||
case LYX_ALIGN_DECIMAL: {
|
||||
Language const *tlang = buffer().paragraphs().front().getParLanguage(buffer().params());
|
||||
attr << "char' char='" << to_utf8(tlang->decimalSeparator());
|
||||
}
|
||||
break;
|
||||
case LYX_ALIGN_LEFT:
|
||||
attr << "left";
|
||||
break;
|
||||
case LYX_ALIGN_RIGHT:
|
||||
attr << "right";
|
||||
break;
|
||||
default:
|
||||
attr << "center";
|
||||
break;
|
||||
}
|
||||
attr << "' " << getVAlignAsXmlAttribute(cell);
|
||||
attr << getHAlignAsXmlAttribute(cell, false) << " " << getVAlignAsXmlAttribute(cell);
|
||||
|
||||
if (isMultiColumn(cell))
|
||||
attr << " colspan='" << columnSpan(cell) << "'";
|
||||
@ -3713,28 +3720,7 @@ void Tabular::docbookRowAsCALS(XMLStream & xs, row_type row,
|
||||
|
||||
stringstream attr;
|
||||
|
||||
attr << "align='";
|
||||
switch (getAlignment(cell)) {
|
||||
case LYX_ALIGN_BLOCK:
|
||||
attr << "justify";
|
||||
break;
|
||||
case LYX_ALIGN_DECIMAL: {
|
||||
Language const *tlang = buffer().paragraphs().front().getParLanguage(buffer().params());
|
||||
attr << "char' char='" << to_utf8(tlang->decimalSeparator());
|
||||
}
|
||||
break;
|
||||
case LYX_ALIGN_LEFT:
|
||||
attr << "left";
|
||||
break;
|
||||
case LYX_ALIGN_RIGHT:
|
||||
attr << "right";
|
||||
break;
|
||||
|
||||
default:
|
||||
attr << "center";
|
||||
break;
|
||||
}
|
||||
attr << "' " << getVAlignAsXmlAttribute(cell);
|
||||
attr << getHAlignAsXmlAttribute(cell, false) << " " << getVAlignAsXmlAttribute(cell);
|
||||
|
||||
if (isMultiColumn(cell))
|
||||
attr << " colspan='" << columnSpan(cell) << "'";
|
||||
@ -3874,19 +3860,7 @@ docstring Tabular::xhtmlRow(XMLStream & xs, row_type row,
|
||||
attr << "style=\"width: " << hwidth << ";\" ";
|
||||
}
|
||||
|
||||
attr << "align='";
|
||||
switch (getAlignment(cell)) {
|
||||
case LYX_ALIGN_LEFT:
|
||||
attr << "left";
|
||||
break;
|
||||
case LYX_ALIGN_RIGHT:
|
||||
attr << "right";
|
||||
break;
|
||||
default:
|
||||
attr << "center";
|
||||
break;
|
||||
}
|
||||
attr << "' " << getVAlignAsXmlAttribute(cell);
|
||||
attr << getHAlignAsXmlAttribute(cell, true) << " " << getVAlignAsXmlAttribute(cell);
|
||||
|
||||
if (isMultiColumn(cell))
|
||||
attr << " colspan='" << columnSpan(cell) << "'";
|
||||
|
@ -946,6 +946,8 @@ public:
|
||||
docstring xhtmlRow(XMLStream & xs, row_type, OutputParams const &,
|
||||
bool header = false) const;
|
||||
|
||||
/// Transforms the vertical alignment of the given cell as a prebaked XML attribute (for HTML and CALS).
|
||||
std::string getHAlignAsXmlAttribute(idx_type cell, bool is_xhtml = true) const;
|
||||
/// Transforms the vertical alignment of the given cell as a prebaked XML attribute (for HTML and CALS).
|
||||
std::string getVAlignAsXmlAttribute(idx_type cell) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user