[Scummvm-git-logs] scummvm master -> 601e4fa95fa750c5d7398a8e3f9d43fa78182ee5
sev-
noreply at scummvm.org
Thu Sep 28 16:49:41 UTC 2023
This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
96e90ba36c GRAPHICS: MACGUI: Calculate minimal line width
aee4432ea3 GRAPHICS> MACGUI: Refactor line with calculation for MacText
7336aee63e GRAPHICS: MACGUI: Properly calculate minimal line width
601e4fa95f GRAPHICS: MACGUI: Initial code for column width calculation in MacText
Commit: 96e90ba36cc61cdcca5e51371da304dd2f85163e
https://github.com/scummvm/scummvm/commit/96e90ba36cc61cdcca5e51371da304dd2f85163e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-28T18:49:23+02:00
Commit Message:
GRAPHICS: MACGUI: Calculate minimal line width
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index f12d23faaa6..aac2853b1ed 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1177,6 +1177,8 @@ int MacText::getLineWidth(int line, bool enforce, int col) {
int width = _textLines[line].indent + _textLines[line].firstLineIndent;
int height = 0;
int charwidth = 0;
+ int minWidth = 0;
+ bool firstWord = true;
for (uint i = 0; i < _textLines[line].chunks.size(); i++) {
if (enforce && _macFontMode)
@@ -1195,7 +1197,15 @@ int MacText::getLineWidth(int line, bool enforce, int col) {
}
if (!_textLines[line].chunks[i].text.empty()) {
- width += getStringWidth(_textLines[line].chunks[i], _textLines[line].chunks[i].text);
+ int w = getStringWidth(_textLines[line].chunks[i], _textLines[line].chunks[i].text);
+
+ if (firstWord) {
+ minWidth = w + width; // Take indent into account
+ firstWord = false;
+ } else {
+ minWidth = MAX(minWidth, w);
+ }
+ width += w;
charwidth += _textLines[line].chunks[i].text.size();
}
@@ -1204,6 +1214,7 @@ int MacText::getLineWidth(int line, bool enforce, int col) {
_textLines[line].width = width;
+ _textLines[line].minWidth = minWidth;
_textLines[line].height = height;
_textLines[line].charwidth = charwidth;
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 9cb02cb8757..2c4955f147d 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -134,6 +134,7 @@ struct MacTextTableRow {
struct MacTextLine {
int width = -1;
int height = -1;
+ int minWidth = -1;
int y = 0;
int charwidth = -1;
bool paragraphEnd = false;
Commit: aee4432ea363c435e13dc0a035154d59b998ff69
https://github.com/scummvm/scummvm/commit/aee4432ea363c435e13dc0a035154d59b998ff69
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-28T18:49:27+02:00
Commit Message:
GRAPHICS> MACGUI: Refactor line with calculation for MacText
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index aac2853b1ed..40197d55494 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -1154,50 +1154,54 @@ int MacText::getLineWidth(int line, bool enforce, int col) {
if ((uint)line >= _textLines.size())
return 0;
- if (_textLines[line].width != -1 && !enforce && col == -1)
- return _textLines[line].width;
+ return getLineWidth(&_textLines[line], enforce, col);
+}
+
+int MacText::getLineWidth(MacTextLine *line, bool enforce, int col) {
+ if (line->width != -1 && !enforce && col == -1)
+ return line->width;
- if (!_textLines[line].picfname.empty()) {
- const Surface *image = getImageSurface(_textLines[line].picfname);
+ if (!line->picfname.empty()) {
+ const Surface *image = getImageSurface(line->picfname);
if (image) {
- float ratio = _maxWidth * _textLines[line].picpercent / 100.0 / (float)image->w;
- _textLines[line].width = _maxWidth;
- _textLines[line].height = image->h * ratio;
- _textLines[line].charwidth = image->w * ratio;
+ float ratio = _maxWidth * line->picpercent / 100.0 / (float)image->w;
+ line->width = _maxWidth;
+ line->height = image->h * ratio;
+ line->charwidth = image->w * ratio;
} else {
- _textLines[line].width = _maxWidth;
- _textLines[line].height = 1;
- _textLines[line].charwidth = 1;
+ line->width = _maxWidth;
+ line->height = 1;
+ line->charwidth = 1;
}
- return _textLines[line].width;
+ return line->width;
}
- int width = _textLines[line].indent + _textLines[line].firstLineIndent;
+ int width = line->indent + line->firstLineIndent;
int height = 0;
int charwidth = 0;
int minWidth = 0;
bool firstWord = true;
- for (uint i = 0; i < _textLines[line].chunks.size(); i++) {
+ for (uint i = 0; i < line->chunks.size(); i++) {
if (enforce && _macFontMode)
- _textLines[line].chunks[i].font = nullptr;
+ line->chunks[i].font = nullptr;
if (col >= 0) {
- if (col >= (int)_textLines[line].chunks[i].text.size()) {
- col -= _textLines[line].chunks[i].text.size();
+ if (col >= (int)line->chunks[i].text.size()) {
+ col -= line->chunks[i].text.size();
} else {
- Common::U32String tmp = _textLines[line].chunks[i].text.substr(0, col);
+ Common::U32String tmp = line->chunks[i].text.substr(0, col);
- width += getStringWidth(_textLines[line].chunks[i], tmp);
+ width += getStringWidth(line->chunks[i], tmp);
return width;
}
}
- if (!_textLines[line].chunks[i].text.empty()) {
- int w = getStringWidth(_textLines[line].chunks[i], _textLines[line].chunks[i].text);
+ if (!line->chunks[i].text.empty()) {
+ int w = getStringWidth(line->chunks[i], line->chunks[i].text);
if (firstWord) {
minWidth = w + width; // Take indent into account
@@ -1206,17 +1210,17 @@ int MacText::getLineWidth(int line, bool enforce, int col) {
minWidth = MAX(minWidth, w);
}
width += w;
- charwidth += _textLines[line].chunks[i].text.size();
+ charwidth += line->chunks[i].text.size();
}
- height = MAX(height, _textLines[line].chunks[i].getFont()->getFontHeight());
+ height = MAX(height, line->chunks[i].getFont()->getFontHeight());
}
- _textLines[line].width = width;
- _textLines[line].minWidth = minWidth;
- _textLines[line].height = height;
- _textLines[line].charwidth = charwidth;
+ line->width = width;
+ line->minWidth = minWidth;
+ line->height = height;
+ line->charwidth = charwidth;
return width;
}
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 2c4955f147d..759d82a0755 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -339,6 +339,8 @@ private:
*/
int getLineWidth(int line, bool enforce = false, int col = -1);
+ int getLineWidth(MacTextLine *line, bool enforce = false, int col = -1);
+
/**
* Rewraps paragraph containing given text row.
* When text is modified, we redo whole thing again without touching
Commit: 7336aee63ec736b86f1d85b9b3800e8b33705b49
https://github.com/scummvm/scummvm/commit/7336aee63ec736b86f1d85b9b3800e8b33705b49
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-28T18:49:27+02:00
Commit Message:
GRAPHICS: MACGUI: Properly calculate minimal line width
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 40197d55494..cbd8216af77 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -21,6 +21,7 @@
#include "common/file.h"
#include "common/timer.h"
+#include "common/tokenizer.h"
#include "common/unicode-bidi.h"
#include "common/compression/unzip.h"
@@ -306,6 +307,33 @@ int MacText::getStringWidth(MacFontRun &format, const Common::U32String &str) {
return format.getFont()->getStringWidth(str);
}
+int MacText::getStringMaxWordWidth(MacFontRun &format, const Common::U32String &str) {
+ if (format.plainByteMode()) {
+ Common::StringTokenizer tok(Common::convertFromU32String(str, format.getEncoding()));
+ int maxW = 0;
+
+ while (!tok.empty()) {
+ int w = format.getFont()->getStringWidth(tok.nextToken());
+
+ maxW = MAX(maxW, w);
+ }
+
+ return maxW;
+ } else {
+ Common::U32StringTokenizer tok(str);
+ int maxW = 0;
+
+ while (!tok.empty()) {
+ int w = format.getFont()->getStringWidth(tok.nextToken());
+
+ maxW = MAX(maxW, w);
+ }
+
+ return maxW;
+ }
+}
+
+
void MacText::setMaxWidth(int maxWidth) {
if (maxWidth == _maxWidth)
return;
@@ -1202,12 +1230,13 @@ int MacText::getLineWidth(MacTextLine *line, bool enforce, int col) {
if (!line->chunks[i].text.empty()) {
int w = getStringWidth(line->chunks[i], line->chunks[i].text);
+ int mW = getStringMaxWordWidth(line->chunks[i], line->chunks[i].text);
if (firstWord) {
- minWidth = w + width; // Take indent into account
+ minWidth = mW + width; // Take indent into account
firstWord = false;
} else {
- minWidth = MAX(minWidth, w);
+ minWidth = MAX(minWidth, mW);
}
width += w;
charwidth += line->chunks[i].text.size();
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 759d82a0755..90d07d61586 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -264,6 +264,7 @@ private:
void insertTextFromClipboard();
// getStringWidth for mactext version, because we may have the plain bytes mode
int getStringWidth(MacFontRun &format, const Common::U32String &str);
+ int getStringMaxWordWidth(MacFontRun &format, const Common::U32String &str);
int getAlignOffset(int row);
MacFontRun getFgColor();
Commit: 601e4fa95fa750c5d7398a8e3f9d43fa78182ee5
https://github.com/scummvm/scummvm/commit/601e4fa95fa750c5d7398a8e3f9d43fa78182ee5
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-28T18:49:27+02:00
Commit Message:
GRAPHICS: MACGUI: Initial code for column width calculation in MacText
Changed paths:
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index cbd8216af77..0cc6a3a64b8 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -935,6 +935,8 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
} else if (cmd == 'B') { // Body end
_inTable = false;
+ processTable(curLine);
+
curTextLine = &_textLines[curLine];
} else if (cmd == 'r') { // Row
curTextLine->table->push_back(MacTextTableRow());
@@ -2859,4 +2861,93 @@ const Surface *MacText::getImageSurface(Common::String &fname) {
#endif // USE_PNG
}
+void MacText::processTable(int line) {
+ Common::Array<MacTextTableRow> *table = _textLines[line].table;
+ uint numCols = table->front().cells.size();
+ Common::Array<int> maxW(numCols), maxL(numCols), colW(numCols);
+ Common::Array<bool> flex(numCols), wrap(numCols);
+
+ int width = _maxWidth * 0.9;
+ int gutter = 10;
+
+ // Compute column widths, both minimal and maximal
+ for (auto &row : *table) {
+ int i = 0;
+ for (auto &cell : row.cells) {
+ int cW = 0, cL = 0;
+ for (auto &l : cell.text) {
+ (void)getLineWidth(&l); // calculate it
+
+ cW = MAX(cW, l.width);
+ cL = MAX(cL, l.minWidth);
+ }
+
+ maxW[i] = MAX(maxW[i], cW);
+ maxL[i] = MAX(maxL[i], cL);
+
+ i++;
+ }
+ }
+
+ for (int i = 0; i < numCols; i++) {
+ warning("%d: %d - %d", i, maxL[i], maxW[i]);
+
+ wrap[i] = (maxW[i] != maxL[i]);
+ }
+
+ int left = width - (numCols - 1) * gutter;
+ int avg = left / numCols;
+ int nflex = 0;
+
+ // determine whether columns should be flexible and assign
+ // width of non-flexible cells
+ for (int i = 0; i < numCols; i++) {
+ flex[i] = (maxW[i] > 2 * avg);
+ if (flex[i]) {
+ nflex++;
+ } else {
+ colW[i] = maxW[i];
+ left -= colW[i];
+ }
+ }
+
+ // if there is not enough space, make columns that could
+ // be word-wrapped flexible, too
+ if (left < nflex * avg) {
+ for (int i = 0; i < numCols; i++) {
+ if (!flex[i] && wrap[i]) {
+ left += colW[i];
+ colW[i] = 0;
+ flex[i] = true;
+ nflex += 1;
+ }
+ }
+ }
+
+ // Calculate weights for flexible columns. The max width
+ // is capped at the page width to treat columns that have to
+ // be wrapped more or less equal
+ int tot = 0;
+ for (int i = 0; i < numCols; i++) {
+ if (flex[i]) {
+ maxW[i] = MIN(maxW[i], width);
+ tot += maxW[i];
+ }
+ }
+
+ // Now assign the actual width for flexible columns. Make
+ // sure that it is at least as long as the longest word length
+ for (int i = 0; i < numCols; i++) {
+ if (flex[i]) {
+ colW[i] = left * maxW[i] / tot;
+ colW[i] = MAX(colW[i], maxL[i]);
+ left -= colW[i];
+ }
+ }
+
+ for (int i = 0; i < numCols; i++) {
+ warning("%d: %d", i, colW[i]);
+ }
+}
+
} // End of namespace Graphics
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 90d07d61586..e247a4cebf2 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -362,6 +362,8 @@ private:
void startMarking(int x, int y);
void updateTextSelection(int x, int y);
+ void processTable(int line);
+
public:
int _cursorX, _cursorY;
bool _cursorState;
More information about the Scummvm-git-logs
mailing list