mirror of
https://github.com/encounter/engine.git
synced 2026-07-10 03:18:43 -07:00
Revert "[web] Calculate align offset for each paragraph line (LineMetrics.left) (#14537)"
This reverts commit 1ecfdcb94c.
This commit is contained in:
@@ -666,7 +666,6 @@ class BitmapCanvas extends EngineCanvas with SaveStackTracking {
|
||||
double x,
|
||||
double y,
|
||||
) {
|
||||
x += line.left;
|
||||
final double letterSpacing = style.letterSpacing;
|
||||
if (letterSpacing == null || letterSpacing == 0.0) {
|
||||
ctx.fillText(line.text, x, y);
|
||||
@@ -713,10 +712,11 @@ class BitmapCanvas extends EngineCanvas with SaveStackTracking {
|
||||
}
|
||||
_applyPaint(paragraph._paint.paintData);
|
||||
|
||||
final double x = offset.dx + paragraph._alignOffset;
|
||||
double y = offset.dy + paragraph.alphabeticBaseline;
|
||||
final int len = lines.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
_drawTextLine(style, lines[i], offset.dx, y);
|
||||
_drawTextLine(style, lines[i], x, y);
|
||||
y += paragraph._lineHeight;
|
||||
}
|
||||
_resetPaint();
|
||||
|
||||
@@ -416,11 +416,6 @@ class DomTextMeasurementService extends TextMeasurementService {
|
||||
List<EngineLineMetrics> lines;
|
||||
if (text != null) {
|
||||
final double lineWidth = maxIntrinsicWidth;
|
||||
final double alignOffset = _calculateAlignOffsetForLine(
|
||||
paragraph: paragraph,
|
||||
lineWidth: lineWidth,
|
||||
maxWidth: width,
|
||||
);
|
||||
lines = <EngineLineMetrics>[
|
||||
EngineLineMetrics.withText(
|
||||
text,
|
||||
@@ -428,7 +423,6 @@ class DomTextMeasurementService extends TextMeasurementService {
|
||||
endIndex: text.length,
|
||||
hardBreak: true,
|
||||
width: lineWidth,
|
||||
left: alignOffset,
|
||||
lineNumber: 0,
|
||||
),
|
||||
];
|
||||
@@ -446,8 +440,6 @@ class DomTextMeasurementService extends TextMeasurementService {
|
||||
alphabeticBaseline: alphabeticBaseline,
|
||||
ideographicBaseline: ideographicBaseline,
|
||||
lines: lines,
|
||||
textAlign: paragraph._textAlign,
|
||||
textDirection: paragraph._textDirection,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -496,8 +488,6 @@ class DomTextMeasurementService extends TextMeasurementService {
|
||||
alphabeticBaseline: alphabeticBaseline,
|
||||
ideographicBaseline: ideographicBaseline,
|
||||
lines: null,
|
||||
textAlign: paragraph._textAlign,
|
||||
textDirection: paragraph._textDirection,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -556,7 +546,7 @@ class CanvasTextMeasurementService extends TextMeasurementService {
|
||||
// TODO(mdebbar): Check if the whole text can fit in a single-line. Then avoid all this ceremony.
|
||||
_canvasContext.font = style.cssFontString;
|
||||
final LinesCalculator linesCalculator =
|
||||
LinesCalculator(_canvasContext, paragraph, constraints.width);
|
||||
LinesCalculator(_canvasContext, text, style, constraints.width);
|
||||
final MinIntrinsicCalculator minIntrinsicCalculator =
|
||||
MinIntrinsicCalculator(_canvasContext, text, style);
|
||||
final MaxIntrinsicCalculator maxIntrinsicCalculator =
|
||||
@@ -607,8 +597,6 @@ class CanvasTextMeasurementService extends TextMeasurementService {
|
||||
maxIntrinsicWidth: maxIntrinsicCalculator.value,
|
||||
width: constraints.width,
|
||||
lines: linesCalculator.lines,
|
||||
textAlign: paragraph._textAlign,
|
||||
textDirection: paragraph._textDirection,
|
||||
);
|
||||
return result;
|
||||
}
|
||||
@@ -714,18 +702,16 @@ int _excludeTrailing(String text, int start, int end, CharPredicate predicate) {
|
||||
/// During the text layout phase, this class splits the lines of text so that it
|
||||
/// ends up fitting into the given width constraint.
|
||||
///
|
||||
/// It implements the Flutter engine's behavior when it comes to handling
|
||||
/// ellipsis and max lines.
|
||||
/// It mimicks the Flutter engine's behavior when it comes to handling ellipsis
|
||||
/// and max lines.
|
||||
class LinesCalculator {
|
||||
LinesCalculator(this._canvasContext, this._paragraph, this._maxWidth);
|
||||
LinesCalculator(this._canvasContext, this._text, this._style, this._maxWidth);
|
||||
|
||||
final html.CanvasRenderingContext2D _canvasContext;
|
||||
final EngineParagraph _paragraph;
|
||||
final String _text;
|
||||
final ParagraphGeometricStyle _style;
|
||||
final double _maxWidth;
|
||||
|
||||
String get _text => _paragraph._plainText;
|
||||
ParagraphGeometricStyle get _style => _paragraph._geometricStyle;
|
||||
|
||||
/// The lines that have been consumed so far.
|
||||
List<EngineLineMetrics> lines = <EngineLineMetrics>[];
|
||||
|
||||
@@ -782,20 +768,12 @@ class LinesCalculator {
|
||||
start: _lineStart,
|
||||
end: chunkEndWithoutSpace,
|
||||
);
|
||||
final double widthOfResultingLine =
|
||||
measureSubstring(_lineStart, breakingPoint) + _ellipsisWidth;
|
||||
final double alignOffset = _calculateAlignOffsetForLine(
|
||||
paragraph: _paragraph,
|
||||
lineWidth: widthOfResultingLine,
|
||||
maxWidth: _maxWidth,
|
||||
);
|
||||
lines.add(EngineLineMetrics.withText(
|
||||
_text.substring(_lineStart, breakingPoint) + _style.ellipsis,
|
||||
startIndex: _lineStart,
|
||||
endIndex: chunkEnd,
|
||||
hardBreak: false,
|
||||
width: widthOfResultingLine,
|
||||
left: alignOffset,
|
||||
width: measureSubstring(_lineStart, breakingPoint) + _ellipsisWidth,
|
||||
lineNumber: lines.length,
|
||||
));
|
||||
} else if (isChunkTooLong) {
|
||||
@@ -848,19 +826,12 @@ class LinesCalculator {
|
||||
_whitespacePredicate,
|
||||
);
|
||||
final int lineNumber = lines.length;
|
||||
final double lineWidth = measureSubstring(_lineStart, endWithoutSpace);
|
||||
final double alignOffset = _calculateAlignOffsetForLine(
|
||||
paragraph: _paragraph,
|
||||
lineWidth: lineWidth,
|
||||
maxWidth: _maxWidth,
|
||||
);
|
||||
final EngineLineMetrics metrics = EngineLineMetrics.withText(
|
||||
_text.substring(_lineStart, endWithoutNewlines),
|
||||
startIndex: _lineStart,
|
||||
endIndex: lineEnd,
|
||||
hardBreak: isHardBreak,
|
||||
width: lineWidth,
|
||||
left: alignOffset,
|
||||
width: measureSubstring(_lineStart, endWithoutSpace),
|
||||
lineNumber: lineNumber,
|
||||
);
|
||||
lines.add(metrics);
|
||||
@@ -987,30 +958,3 @@ class MaxIntrinsicCalculator {
|
||||
_lastHardLineEnd = hardLineEnd;
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates the offset necessary for the given line to be correctly aligned.
|
||||
double _calculateAlignOffsetForLine({
|
||||
@required EngineParagraph paragraph,
|
||||
@required double lineWidth,
|
||||
@required double maxWidth,
|
||||
}) {
|
||||
final double emptySpace = maxWidth - lineWidth;
|
||||
// WARNING: the [paragraph] may not be laid out yet at this point. This
|
||||
// function must not use layout metrics, such as [paragraph.height].
|
||||
switch (paragraph._textAlign) {
|
||||
case ui.TextAlign.center:
|
||||
return emptySpace / 2.0;
|
||||
case ui.TextAlign.right:
|
||||
return emptySpace;
|
||||
case ui.TextAlign.start:
|
||||
return paragraph._textDirection == ui.TextDirection.rtl
|
||||
? emptySpace
|
||||
: 0.0;
|
||||
case ui.TextAlign.end:
|
||||
return paragraph._textDirection == ui.TextDirection.rtl
|
||||
? 0.0
|
||||
: emptySpace;
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,12 @@ class EngineLineMetrics implements ui.LineMetrics {
|
||||
this.unscaledAscent,
|
||||
this.height,
|
||||
@required this.width,
|
||||
@required this.left,
|
||||
this.left,
|
||||
this.baseline,
|
||||
@required this.lineNumber,
|
||||
}) : assert(text != null),
|
||||
assert(hardBreak != null),
|
||||
assert(width != null),
|
||||
assert(left != null),
|
||||
assert(lineNumber != null && lineNumber >= 0);
|
||||
|
||||
/// The textual content representing this line.
|
||||
|
||||
@@ -800,9 +800,7 @@ class ParagraphRuler {
|
||||
final int len = constraintCache.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
final MeasurementResult item = constraintCache[i];
|
||||
if (item.constraintWidth == constraints.width &&
|
||||
item.textAlign == paragraph._textAlign &&
|
||||
item.textDirection == paragraph._textDirection) {
|
||||
if (item.constraintWidth == constraints.width) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -854,13 +852,7 @@ class MeasurementResult {
|
||||
/// of each laid out line.
|
||||
final List<EngineLineMetrics> lines;
|
||||
|
||||
/// The text align value of the paragraph.
|
||||
final ui.TextAlign textAlign;
|
||||
|
||||
/// The text direction of the paragraph.
|
||||
final ui.TextDirection textDirection;
|
||||
|
||||
MeasurementResult(
|
||||
const MeasurementResult(
|
||||
this.constraintWidth, {
|
||||
@required this.isSingleLine,
|
||||
@required this.width,
|
||||
@@ -872,8 +864,6 @@ class MeasurementResult {
|
||||
@required this.alphabeticBaseline,
|
||||
@required this.ideographicBaseline,
|
||||
@required this.lines,
|
||||
@required this.textAlign,
|
||||
@required this.textDirection,
|
||||
}) : assert(constraintWidth != null),
|
||||
assert(isSingleLine != null),
|
||||
assert(width != null),
|
||||
@@ -882,7 +872,5 @@ class MeasurementResult {
|
||||
assert(minIntrinsicWidth != null),
|
||||
assert(maxIntrinsicWidth != null),
|
||||
assert(alphabeticBaseline != null),
|
||||
assert(ideographicBaseline != null),
|
||||
assert(textAlign != null),
|
||||
assert(textDirection != null);
|
||||
assert(ideographicBaseline != null);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user