XHTML/DocBook: merge code duplicates for vertical alignment.

This commit is contained in:
Thibaut Cuvelier 2022-04-01 03:51:24 +02:00
parent 7b6afb23ec
commit c7896cf922
2 changed files with 19 additions and 39 deletions

View File

@ -3626,6 +3626,19 @@ void Tabular::docbookRow(XMLStream & xs, row_type row,
} }
std::string Tabular::getVAlignAsXmlAttribute(idx_type cell) const
{
switch (getVAlignment(cell)) {
case LYX_VALIGN_TOP:
return "valign='top'";
case LYX_VALIGN_BOTTOM:
return "valign='bottom'";
case LYX_VALIGN_MIDDLE:
return "valign='middle'";
}
}
void Tabular::docbookRowAsHTML(XMLStream & xs, row_type row, void Tabular::docbookRowAsHTML(XMLStream & xs, row_type row,
OutputParams const & runparams, bool header) const OutputParams const & runparams, bool header) const
{ {
@ -3666,19 +3679,7 @@ void Tabular::docbookRowAsHTML(XMLStream & xs, row_type row,
attr << "center"; attr << "center";
break; break;
} }
attr << "'"; attr << "' " << getVAlignAsXmlAttribute(cell);
attr << " valign='";
switch (getVAlignment(cell)) {
case LYX_VALIGN_TOP:
attr << "top";
break;
case LYX_VALIGN_BOTTOM:
attr << "bottom";
break;
case LYX_VALIGN_MIDDLE:
attr << "middle";
}
attr << "'";
if (isMultiColumn(cell)) if (isMultiColumn(cell))
attr << " colspan='" << columnSpan(cell) << "'"; attr << " colspan='" << columnSpan(cell) << "'";
@ -3733,19 +3734,7 @@ void Tabular::docbookRowAsCALS(XMLStream & xs, row_type row,
attr << "center"; attr << "center";
break; break;
} }
attr << "'"; attr << "' " << getVAlignAsXmlAttribute(cell);
attr << " valign='";
switch (getVAlignment(cell)) {
case LYX_VALIGN_TOP:
attr << "top";
break;
case LYX_VALIGN_BOTTOM:
attr << "bottom";
break;
case LYX_VALIGN_MIDDLE:
attr << "middle";
}
attr << "'";
if (isMultiColumn(cell)) if (isMultiColumn(cell))
attr << " colspan='" << columnSpan(cell) << "'"; attr << " colspan='" << columnSpan(cell) << "'";
@ -3897,19 +3886,7 @@ docstring Tabular::xhtmlRow(XMLStream & xs, row_type row,
attr << "center"; attr << "center";
break; break;
} }
attr << "'"; attr << "' " << getVAlignAsXmlAttribute(cell);
attr << " valign='";
switch (getVAlignment(cell)) {
case LYX_VALIGN_TOP:
attr << "top";
break;
case LYX_VALIGN_BOTTOM:
attr << "bottom";
break;
case LYX_VALIGN_MIDDLE:
attr << "middle";
}
attr << "'";
if (isMultiColumn(cell)) if (isMultiColumn(cell))
attr << " colspan='" << columnSpan(cell) << "'"; attr << " colspan='" << columnSpan(cell) << "'";

View File

@ -946,6 +946,9 @@ public:
docstring xhtmlRow(XMLStream & xs, row_type, OutputParams const &, docstring xhtmlRow(XMLStream & xs, row_type, OutputParams const &,
bool header = false) const; bool header = false) 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;
/// change associated Buffer /// change associated Buffer
void setBuffer(Buffer & buffer); void setBuffer(Buffer & buffer);
/// retrieve associated Buffer /// retrieve associated Buffer