::const_iterator next = it;
++next;
if (next == TL.end() || next->yp != it->yp)
offsetY += 7;
}
++it;
}
fout << "";
char bf1[256];
char bf2[256];
GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, bf2, 256);
GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, bf1, 256);
//fout << "Skapad av MeOS: " << bf1 << " "<< bf2 << "\n";
fout << toUTF8(lang.tl("Skapad av ")) + "MeOS: " << bf1 << " "<< bf2 << "\n";
fout << "
\n";
fout << "\n";
fout << "\n";
return false;
}
string html_table_code(const string &in)
{
if (in.size()==0)
return " ";
else {
return encodeXML(in);
}
}
bool sortTL_X(const TextInfo *a, const TextInfo *b)
{
return a->xp < b->xp;
}
bool gdioutput::writeTableHTML(const wstring &file,
const string &title, int refreshTimeOut) const
{
ofstream fout(file.c_str());
if (fout.bad())
return false;
return writeTableHTML(fout, title, false, refreshTimeOut);
}
bool gdioutput::writeTableHTML(ostream &fout,
const string &title,
bool simpleFormat,
int refreshTimeOut) const {
fout << "\n\n";
fout << "\n\n";
fout << "\n";
if (refreshTimeOut > 0)
fout << "\n";
fout << "" << toUTF8(title) << "\n";
map< pair, pair > styles;
generateStyles(fout, true, TL, styles);
fout << "\n";
fout << "\n";
list::const_iterator it = TL.begin();
map tableCoordinates;
//Get x-coordinates
while (it!=TL.end()) {
tableCoordinates[it->xp]=0;
++it;
}
map::iterator mit=tableCoordinates.begin();
int k=0;
while (mit!=tableCoordinates.end()) {
mit->second=k++;
++mit;
}
tableCoordinates[MaxX]=k;
vector sizeSet(k+1, false);
fout << "\n";
int linecounter=0;
it=TL.begin();
vector< pair > > rows;
rows.reserve(TL.size() / 3);
vector ypRow;
int minHeight = 100000;
while (it!=TL.end()) {
int y=it->yp;
vector row;
int subnormal = 0;
int normal = 0;
int header = 0;
int mainheader = 0;
while (it!=TL.end() && it->yp==y) {
if (!gdioutput::skipTextRender(it->format)) {
row.push_back(&*it);
switch (it->getGdiFont()) {
case fontLarge:
case boldLarge:
case boldHuge:
mainheader++;
break;
case boldText:
case italicMediumPlus:
case fontMediumPlus:
header++;
break;
case fontSmall:
case italicSmall:
subnormal++;
break;
default:
normal++;
}
}
++it;
}
if (row.empty())
continue;
bool isMainHeader = mainheader > normal;
bool isHeader = (header + mainheader) > normal;
bool isSub = subnormal > normal;
sort(row.begin(), row.end(), sortTL_X);
rows.resize(rows.size() + 1);
rows.back().first = isMainHeader ? 1 : (isHeader ? 2 : (isSub ? 3 : 0));
rows.back().second.swap(row);
int last = ypRow.size();
ypRow.push_back(y);
if (last > 0) {
minHeight = min(minHeight, ypRow[last] - ypRow[last-1]);
}
}
int numMin = 0;
for (size_t gCount = 1; gCount < rows.size(); gCount++) {
int h = ypRow[gCount] - ypRow[gCount-1];
if (h == minHeight)
numMin++;
}
if (numMin == 0)
numMin = 1;
int hdrLimit = (rows.size() / numMin) <= 4 ? int(minHeight * 1.2) : int(minHeight * 1.5);
for (size_t gCount = 1; gCount + 1 < rows.size(); gCount++) {
int type = rows[gCount].first;
int lastType = gCount > 0 ? rows[gCount-1].first : 0;
int nextType = gCount + 1 < rows.size() ? rows[gCount + 1].first : 0;
if (type == 0 && (lastType == 1 || lastType == 2) && (nextType == 1 || nextType == 2))
continue; // No reclassify
int h = ypRow[gCount] - ypRow[gCount-1];
if (h > hdrLimit && rows[gCount].first == 0)
rows[gCount].first = 2;
}
ypRow.clear();
string lineclass;
for (size_t gCount = 0; gCount < rows.size(); gCount++) {
vector &row = rows[gCount].second;
int type = rows[gCount].first;
int lastType = gCount > 0 ? rows[gCount-1].first : 0;
int nextType = gCount + 1 < rows.size() ? rows[gCount + 1].first : 0;
vector::iterator rit;
fout << "" << endl;
if (simpleFormat) {
}
else if (type == 1) {
lineclass = " class=\"freeheader\"";
linecounter = 0;
}
else if (type == 2) {
linecounter = 0;
lineclass = " valign=\"bottom\" class=\"header\"";
}
else {
if (type == 3)
linecounter = 1;
if ((lastType == 1 || lastType == 2) && (nextType == 1 || nextType == 2) && row.size() < 3) {
lineclass = "";
}
else
lineclass = (linecounter&1) ? " class=\"e1\"" : " class=\"e0\"";
linecounter++;
}
for (size_t k=0;kxp];
if (k==0 && thisCol!=0)
fout << "| | ";
int nextCol;
if (row.size()==k+1)
nextCol=tableCoordinates.rbegin()->second;
else
nextCol=tableCoordinates[row[k+1]->xp];
int colspan=nextCol-thisCol;
assert(colspan>0);
string style;
if (row[k]->format&textRight)
style=" style=\"text-align:right\"";
if (colspan==1 && !sizeSet[thisCol]) {
fout << " xp - row[k]->xp) : (MaxX-row[k]->xp)) << "\">";
sizeSet[thisCol]=true;
}
else if (colspan>1)
fout << " | ";
else
fout << " | ";
gdiFonts font = row[k]->getGdiFont();
string starttag, endtag;
getStyle(styles, font, row[k]->font, "", starttag, endtag);
fout << starttag << toUTF8(html_table_code(row[k]->text)) << endtag << " | " << endl;
}
fout << "
\n";
row.clear();
}
fout << "
\n";
if (!simpleFormat) {
fout << "
";
char bf1[256];
char bf2[256];
GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, bf2, 256);
GetDateFormat(LOCALE_USER_DEFAULT, 0, NULL, NULL, bf1, 256);
string meos = getMeosCompectVersion();
fout << toUTF8(lang.tl("Skapad av ")) + "MeOS "
<< meos << ": " << bf1 << " "<< bf2 << "\n";
fout << "
\n";
}
fout << "\n";
fout << "\n";
return true;
}