Skip to content

Commit

Permalink
Revert breaking PRs (flutter#16148)
Browse files Browse the repository at this point in the history
* Revert "Web PargraphStyle TextHeightBehavior integration (flutter#16075)"

This reverts commit 86682a2.

* Revert "Engine/LibTxt/dart:ui impl of TextHeightBehavior (flutter#15087)"

This reverts commit cbf4536.
  • Loading branch information
dnfield authored Jan 28, 2020
1 parent b4fc4b5 commit 53baa7a
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 438 deletions.
127 changes: 12 additions & 115 deletions lib/ui/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -429,94 +429,6 @@ enum TextDecorationStyle {
wavy
}

/// {@template flutter.dart:ui.textHeightBehavior}
/// Defines how the paragraph will apply [TextStyle.height] to the ascent of the
/// first line and descent of the last line.
///
/// Each boolean value represents whether the [TextStyle.height] modifier will
/// be applied to the corresponding metric. By default, all properties are true,
/// and [TextStyle.height] is applied as normal. When set to false, the font's
/// default ascent will be used.
/// {@endtemplate}
class TextHeightBehavior {

/// Creates a new TextHeightBehavior object.
///
/// * applyHeightToFirstAscent: When true, the [TextStyle.height] modifier
/// will be applied to the ascent of the first line. When false, the font's
/// default ascent will be used.
/// * applyHeightToLastDescent: When true, the [TextStyle.height] modifier
/// will be applied to the descent of the last line. When false, the font's
/// default descent will be used.
///
/// All properties default to true (height modifications applied as normal).
const TextHeightBehavior({
this.applyHeightToFirstAscent = true,
this.applyHeightToLastDescent = true,
});

/// Creates a new TextHeightBehavior object from an encoded form.
///
/// See [encode] for the creation of the encoded form.
const TextHeightBehavior.fromEncoded(int encoded) : applyHeightToFirstAscent = (encoded & 0x1) == 0,
applyHeightToLastDescent = (encoded & 0x2) == 0;


/// Whether to apply the [TextStyle.height] modifier to the ascent of the first
/// line in the paragraph.
///
/// When true, the [TextStyle.height] modifier will be applied to to the ascent
/// of the first line. When false, the font's default ascent will be used and
/// the [TextStyle.height] will have no effect on the ascent of the first line.
///
/// This property only has effect if a non-null [TextStyle.height] is specified.
///
/// Defaults to true (height modifications applied as normal).
final bool applyHeightToFirstAscent;

/// Whether to apply the [TextStyle.height] modifier to the descent of the last
/// line in the paragraph.
///
/// When true, the [TextStyle.height] modifier will be applied to to the descent
/// of the last line. When false, the font's default descent will be used and
/// the [TextStyle.height] will have no effect on the descent of the last line.
///
/// This property only has effect if a non-null [TextStyle.height] is specified.
///
/// Defaults to true (height modifications applied as normal).
final bool applyHeightToLastDescent;

/// Returns an encoded int representation of this object.
int encode() {
return (applyHeightToFirstAscent ? 0 : 1 << 0) | (applyHeightToLastDescent ? 0 : 1 << 1);
}

@override
bool operator ==(dynamic other) {
if (other.runtimeType != runtimeType)
return false;
return other is TextHeightBehavior
&& other.applyHeightToFirstAscent == applyHeightToFirstAscent
&& other.applyHeightToLastDescent == applyHeightToLastDescent;
}

@override
int get hashCode {
return hashValues(
applyHeightToFirstAscent,
applyHeightToLastDescent,
);
}

@override
String toString() {
return 'TextHeightBehavior('
'applyHeightToFirstAscent: $applyHeightToFirstAscent, '
'applyHeightToLastDescent: $applyHeightToLastDescent'
')';
}
}

/// Determines if lists [a] and [b] are deep equivalent.
///
/// Returns true if the lists are both null, or if they are both non-null, have
Expand Down Expand Up @@ -834,23 +746,20 @@ class TextStyle {
//
// - Element 5: The value of |maxLines|.
//
// - Element 6: The encoded value of |textHeightBehavior|.
//
Int32List _encodeParagraphStyle(
TextAlign textAlign,
TextDirection textDirection,
int maxLines,
String fontFamily,
double fontSize,
double height,
TextHeightBehavior textHeightBehavior,
FontWeight fontWeight,
FontStyle fontStyle,
StrutStyle strutStyle,
String ellipsis,
Locale locale,
) {
final Int32List result = Int32List(7); // also update paragraph_builder.cc
final Int32List result = Int32List(6); // also update paragraph_builder.cc
if (textAlign != null) {
result[0] |= 1 << 1;
result[1] = textAlign.index;
Expand All @@ -871,32 +780,28 @@ Int32List _encodeParagraphStyle(
result[0] |= 1 << 5;
result[5] = maxLines;
}
if (textHeightBehavior != null) {
result[0] |= 1 << 6;
result[6] = textHeightBehavior.encode();
}
if (fontFamily != null) {
result[0] |= 1 << 7;
result[0] |= 1 << 6;
// Passed separately to native.
}
if (fontSize != null) {
result[0] |= 1 << 8;
result[0] |= 1 << 7;
// Passed separately to native.
}
if (height != null) {
result[0] |= 1 << 9;
result[0] |= 1 << 8;
// Passed separately to native.
}
if (strutStyle != null) {
result[0] |= 1 << 10;
result[0] |= 1 << 9;
// Passed separately to native.
}
if (ellipsis != null) {
result[0] |= 1 << 11;
result[0] |= 1 << 10;
// Passed separately to native.
}
if (locale != null) {
result[0] |= 1 << 12;
result[0] |= 1 << 11;
// Passed separately to native.
}
return result;
Expand Down Expand Up @@ -937,9 +842,6 @@ class ParagraphStyle {
/// the line height to take the height as defined by the font, which may not
/// be exactly the height of the `fontSize`.
///
/// * `textHeightBehavior`: Specifies how the `height` multiplier is
/// applied to ascent of the first line and the descent of the last line.
///
/// * `fontWeight`: The typeface thickness to use when painting the text
/// (e.g., bold).
///
Expand Down Expand Up @@ -967,7 +869,6 @@ class ParagraphStyle {
String fontFamily,
double fontSize,
double height,
TextHeightBehavior textHeightBehavior,
FontWeight fontWeight,
FontStyle fontStyle,
StrutStyle strutStyle,
Expand All @@ -980,7 +881,6 @@ class ParagraphStyle {
fontFamily,
fontSize,
height,
textHeightBehavior,
fontWeight,
fontStyle,
strutStyle,
Expand Down Expand Up @@ -1029,14 +929,11 @@ class ParagraphStyle {
'fontWeight: ${ _encoded[0] & 0x008 == 0x008 ? FontWeight.values[_encoded[3]] : "unspecified"}, '
'fontStyle: ${ _encoded[0] & 0x010 == 0x010 ? FontStyle.values[_encoded[4]] : "unspecified"}, '
'maxLines: ${ _encoded[0] & 0x020 == 0x020 ? _encoded[5] : "unspecified"}, '
'textHeightBehavior: ${
_encoded[0] & 0x040 == 0x040 ?
TextHeightBehavior.fromEncoded(_encoded[6]).toString() : "unspecified"}, '
'fontFamily: ${ _encoded[0] & 0x080 == 0x080 ? _fontFamily : "unspecified"}, '
'fontSize: ${ _encoded[0] & 0x100 == 0x100 ? _fontSize : "unspecified"}, '
'height: ${ _encoded[0] & 0x200 == 0x200 ? "${_height}x" : "unspecified"}, '
'ellipsis: ${ _encoded[0] & 0x400 == 0x400 ? "\"$_ellipsis\"" : "unspecified"}, '
'locale: ${ _encoded[0] & 0x800 == 0x800 ? _locale : "unspecified"}'
'fontFamily: ${ _encoded[0] & 0x040 == 0x040 ? _fontFamily : "unspecified"}, '
'fontSize: ${ _encoded[0] & 0x080 == 0x080 ? _fontSize : "unspecified"}, '
'height: ${ _encoded[0] & 0x100 == 0x100 ? "${_height}x" : "unspecified"}, '
'ellipsis: ${ _encoded[0] & 0x200 == 0x200 ? "\"$_ellipsis\"" : "unspecified"}, '
'locale: ${ _encoded[0] & 0x400 == 0x400 ? _locale : "unspecified"}'
')';
}
}
Expand Down
18 changes: 6 additions & 12 deletions lib/ui/text/paragraph_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@ const int psTextDirectionIndex = 2;
const int psFontWeightIndex = 3;
const int psFontStyleIndex = 4;
const int psMaxLinesIndex = 5;
const int psTextHeightBehaviorIndex = 6;
const int psFontFamilyIndex = 7;
const int psFontSizeIndex = 8;
const int psHeightIndex = 9;
const int psStrutStyleIndex = 10;
const int psEllipsisIndex = 11;
const int psLocaleIndex = 12;
const int psFontFamilyIndex = 6;
const int psFontSizeIndex = 7;
const int psHeightIndex = 8;
const int psStrutStyleIndex = 9;
const int psEllipsisIndex = 10;
const int psLocaleIndex = 11;

const int psTextAlignMask = 1 << psTextAlignIndex;
const int psTextDirectionMask = 1 << psTextDirectionIndex;
Expand All @@ -91,7 +90,6 @@ const int psMaxLinesMask = 1 << psMaxLinesIndex;
const int psFontFamilyMask = 1 << psFontFamilyIndex;
const int psFontSizeMask = 1 << psFontSizeIndex;
const int psHeightMask = 1 << psHeightIndex;
const int psTextHeightBehaviorMask = 1 << psTextHeightBehaviorIndex;
const int psStrutStyleMask = 1 << psStrutStyleIndex;
const int psEllipsisMask = 1 << psEllipsisIndex;
const int psLocaleMask = 1 << psLocaleIndex;
Expand Down Expand Up @@ -267,10 +265,6 @@ ParagraphBuilder::ParagraphBuilder(
style.has_height_override = true;
}

if (mask & psTextHeightBehaviorMask) {
style.text_height_behavior = encoded[psTextHeightBehaviorIndex];
}

if (mask & psStrutStyleMask) {
decodeStrut(strutData, strutFontFamilies, style);
}
Expand Down
7 changes: 0 additions & 7 deletions lib/web_ui/lib/src/engine/compositor/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class SkParagraphStyle implements ui.ParagraphStyle {
String fontFamily,
double fontSize,
double height,
ui.TextHeightBehavior textHeightBehavior,
ui.FontWeight fontWeight,
ui.FontStyle fontStyle,
ui.StrutStyle strutStyle,
Expand All @@ -39,7 +38,6 @@ class SkParagraphStyle implements ui.ParagraphStyle {
fontFamily,
fontSize,
height,
textHeightBehavior,
fontWeight,
fontStyle,
ellipsis,
Expand Down Expand Up @@ -87,7 +85,6 @@ class SkParagraphStyle implements ui.ParagraphStyle {
String fontFamily,
double fontSize,
double height,
ui.TextHeightBehavior textHeightBehavior,
ui.FontWeight fontWeight,
ui.FontStyle fontStyle,
String ellipsis,
Expand Down Expand Up @@ -132,10 +129,6 @@ class SkParagraphStyle implements ui.ParagraphStyle {
skParagraphStyle['heightMultiplier'] = height;
}

if (textHeightBehavior != null) {
skParagraphStyle['textHeightBehavior'] = textHeightBehavior.encode();
}

if (maxLines != null) {
skParagraphStyle['maxLines'] = maxLines;
}
Expand Down
23 changes: 2 additions & 21 deletions lib/web_ui/lib/src/engine/text/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ class EngineParagraphStyle implements ui.ParagraphStyle {
String fontFamily,
double fontSize,
double height,
ui.TextHeightBehavior textHeightBehavior,
ui.FontWeight fontWeight,
ui.FontStyle fontStyle,
ui.StrutStyle strutStyle,
Expand All @@ -471,7 +470,6 @@ class EngineParagraphStyle implements ui.ParagraphStyle {
_fontFamily = fontFamily,
_fontSize = fontSize,
_height = height,
_textHeightBehavior = textHeightBehavior,
// TODO(b/128317744): add support for strut style.
_strutStyle = strutStyle,
_ellipsis = ellipsis,
Expand All @@ -485,7 +483,6 @@ class EngineParagraphStyle implements ui.ParagraphStyle {
final String _fontFamily;
final double _fontSize;
final double _height;
final ui.TextHeightBehavior _textHeightBehavior;
final EngineStrutStyle _strutStyle;
final String _ellipsis;
final ui.Locale _locale;
Expand Down Expand Up @@ -539,27 +536,13 @@ class EngineParagraphStyle implements ui.ParagraphStyle {
_fontFamily == typedOther._fontFamily ||
_fontSize == typedOther._fontSize ||
_height == typedOther._height ||
_textHeightBehavior == typedOther._textHeightBehavior ||
_ellipsis == typedOther._ellipsis ||
_locale == typedOther._locale;
}

@override
int get hashCode {
return ui.hashValues(
_textAlign,
_textDirection,
_fontWeight,
_fontStyle,
_maxLines,
_fontFamily,
_fontSize,
_height,
_textHeightBehavior,
_ellipsis,
_locale
);
}
int get hashCode =>
ui.hashValues(_fontFamily, _fontSize, _height, _ellipsis, _locale);

@override
String toString() {
Expand All @@ -570,11 +553,9 @@ class EngineParagraphStyle implements ui.ParagraphStyle {
'fontWeight: ${_fontWeight ?? "unspecified"}, '
'fontStyle: ${_fontStyle ?? "unspecified"}, '
'maxLines: ${_maxLines ?? "unspecified"}, '
'textHeightBehavior: ${_textHeightBehavior ?? "unspecified"}, '
'fontFamily: ${_fontFamily ?? "unspecified"}, '
'fontSize: ${_fontSize != null ? _fontSize.toStringAsFixed(1) : "unspecified"}, '
'height: ${_height != null ? "${_height.toStringAsFixed(1)}x" : "unspecified"}, '
'textHeightBehavior: ${_textHeightBehavior ?? "unspecified"}, '
'ellipsis: ${_ellipsis != null ? "\"$_ellipsis\"" : "unspecified"}, '
'locale: ${_locale ?? "unspecified"}'
')';
Expand Down
Loading

0 comments on commit 53baa7a

Please sign in to comment.