[canvaskit] Add halfLeading to TextStyle and StrutStyle
- Add halfLeading (introduced in https://skia-review.googlesource.com/c/skia/+/394969) to canvaskit bindings - Fix wrong initial value of fDescent Change-Id: I01d522cd5a3761f32426038dce2ab82f24c9c529 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/398276 Reviewed-by: Kevin Lubick <kjlubick@google.com> Commit-Queue: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
parent
60191e0502
commit
04c82165b1
@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- `CanvasKit.RuntimeEffect` now supports integer uniforms in the SkSL. These are still passed
|
||||
to `RuntimeEffect.makeShader` as floats (like all other uniforms), and will be converted to
|
||||
integers internally, to match the expectations of the shader.
|
||||
- Add 'halfLeading' to `TextStyle` and `StrutStyle`.
|
||||
|
||||
### Removed
|
||||
- `Picture.saveAsFile()`, in favor of `Picture.serialize()` where clients can control how to
|
||||
|
2
modules/canvaskit/npm_build/types/index.d.ts
vendored
2
modules/canvaskit/npm_build/types/index.d.ts
vendored
@ -2666,6 +2666,7 @@ export interface StrutStyle {
|
||||
fontStyle?: FontStyle;
|
||||
fontSize?: number;
|
||||
heightMultiplier?: number;
|
||||
halfLeading?: boolean;
|
||||
leading?: number;
|
||||
forceStrutHeight?: boolean;
|
||||
}
|
||||
@ -2697,6 +2698,7 @@ export interface TextStyle {
|
||||
fontStyle?: FontStyle;
|
||||
foregroundColor?: InputColor;
|
||||
heightMultiplier?: number;
|
||||
halfLeading?: boolean;
|
||||
letterSpacing?: number;
|
||||
locale?: string;
|
||||
shadows?: TextShadow[];
|
||||
|
@ -101,6 +101,7 @@
|
||||
s['fontStyle'] = fontStyle(s['fontStyle']);
|
||||
s['fontSize'] = s['fontSize'] || 0;
|
||||
s['heightMultiplier'] = s['heightMultiplier'] || 0;
|
||||
s['halfLeading'] = s['halfLeading'] || false;
|
||||
s['leading'] = s['leading'] || 0;
|
||||
s['forceStrutHeight'] = s['forceStrutHeight'] || false;
|
||||
return s;
|
||||
@ -120,6 +121,7 @@
|
||||
s['letterSpacing'] = s['letterSpacing'] || 0;
|
||||
s['wordSpacing'] = s['wordSpacing'] || 0;
|
||||
s['heightMultiplier'] = s['heightMultiplier'] || 0;
|
||||
s['halfLeading'] = s['halfLeading'] || false;
|
||||
if (s['locale']) {
|
||||
var str = s['locale'];
|
||||
s['_localePtr'] = cacheOrCopyString(str);
|
||||
|
@ -52,6 +52,7 @@ struct SimpleTextStyle {
|
||||
SkScalar letterSpacing;
|
||||
SkScalar wordSpacing;
|
||||
SkScalar heightMultiplier;
|
||||
bool halfLeading;
|
||||
uintptr_t /* const char* */ localePtr;
|
||||
int localeLen;
|
||||
SimpleFontStyle fontStyle;
|
||||
@ -75,6 +76,7 @@ struct SimpleStrutStyle {
|
||||
SimpleFontStyle fontStyle;
|
||||
SkScalar fontSize;
|
||||
SkScalar heightMultiplier;
|
||||
bool halfLeading;
|
||||
SkScalar leading;
|
||||
bool strutEnabled;
|
||||
bool forceStrutHeight;
|
||||
@ -102,6 +104,8 @@ para::StrutStyle toStrutStyle(const SimpleStrutStyle& s) {
|
||||
ss.setHeight(s.heightMultiplier);
|
||||
ss.setHeightOverride(true);
|
||||
}
|
||||
ss.setHalfLeading(s.halfLeading);
|
||||
|
||||
if (s.leading != 0) {
|
||||
ss.setLeading(s.leading);
|
||||
}
|
||||
@ -147,6 +151,8 @@ para::TextStyle toTextStyle(const SimpleTextStyle& s) {
|
||||
ts.setHeightOverride(true);
|
||||
}
|
||||
|
||||
ts.setHalfLeading(s.halfLeading);
|
||||
|
||||
ts.setDecoration(para::TextDecoration(s.decoration));
|
||||
ts.setDecorationStyle(s.decorationStyle);
|
||||
if (s.decorationThickness != 0) {
|
||||
@ -475,6 +481,7 @@ EMSCRIPTEN_BINDINGS(Paragraph) {
|
||||
.field("fontSize", &SimpleStrutStyle::fontSize)
|
||||
.field("fontStyle", &SimpleStrutStyle::fontStyle)
|
||||
.field("heightMultiplier", &SimpleStrutStyle::heightMultiplier)
|
||||
.field("halfLeading", &SimpleStrutStyle::halfLeading)
|
||||
.field("leading", &SimpleStrutStyle::leading)
|
||||
.field("forceStrutHeight", &SimpleStrutStyle::forceStrutHeight);
|
||||
|
||||
@ -492,6 +499,7 @@ EMSCRIPTEN_BINDINGS(Paragraph) {
|
||||
.field("letterSpacing", &SimpleTextStyle::letterSpacing)
|
||||
.field("wordSpacing", &SimpleTextStyle::wordSpacing)
|
||||
.field("heightMultiplier", &SimpleTextStyle::heightMultiplier)
|
||||
.field("halfLeading", &SimpleTextStyle::halfLeading)
|
||||
.field("_localePtr", &SimpleTextStyle::localePtr)
|
||||
.field("_localeLen", &SimpleTextStyle::localeLen)
|
||||
.field("fontStyle", &SimpleTextStyle::fontStyle)
|
||||
|
@ -805,6 +805,47 @@ describe('Paragraph Behavior', function() {
|
||||
builder.delete();
|
||||
});
|
||||
|
||||
gm('paragraph_text_styles_mixed_leading_distribution', (canvas) => {
|
||||
const fontMgr = CanvasKit.FontMgr.FromData(notoSerifFontBuffer);
|
||||
expect(fontMgr.countFamilies()).toEqual(1);
|
||||
expect(fontMgr.getFamilyName(0)).toEqual('Noto Serif');
|
||||
|
||||
const wrapTo = 200;
|
||||
|
||||
const paraStyle = new CanvasKit.ParagraphStyle({
|
||||
textStyle: {
|
||||
color: CanvasKit.BLACK,
|
||||
backgroundColor: CanvasKit.Color(234, 208, 232), // light pink
|
||||
fontFamilies: ['Noto Serif'],
|
||||
fontSize: 10,
|
||||
heightMultiplier: 10,
|
||||
},
|
||||
});
|
||||
|
||||
const builder = CanvasKit.ParagraphBuilder.Make(paraStyle, fontMgr);
|
||||
builder.addText('Not half leading');
|
||||
|
||||
const halfLeadingText = new CanvasKit.TextStyle({
|
||||
color: CanvasKit.Color(48, 37, 199),
|
||||
backgroundColor: CanvasKit.Color(234, 208, 232), // light pink
|
||||
fontFamilies: ['Noto Serif'],
|
||||
fontSize: 10,
|
||||
heightMultiplier: 10,
|
||||
halfLeading: true,
|
||||
});
|
||||
builder.pushStyle(halfLeadingText);
|
||||
builder.addText('Half Leading Text');
|
||||
const paragraph = builder.build();
|
||||
|
||||
paragraph.layout(wrapTo);
|
||||
canvas.clear(CanvasKit.WHITE);
|
||||
canvas.drawParagraph(paragraph, 0, 0);
|
||||
|
||||
fontMgr.delete();
|
||||
paragraph.delete();
|
||||
builder.delete();
|
||||
});
|
||||
|
||||
it('should not crash if we omit font family on pushed textStyle', () => {
|
||||
const surface = CanvasKit.MakeCanvasSurface('test');
|
||||
expect(surface).toBeTruthy('Could not make surface');
|
||||
|
@ -70,7 +70,7 @@ public:
|
||||
// for specific runs of text can be obtained in run_metrics_map. These values
|
||||
// are the cumulative metrics for the entire line.
|
||||
double fAscent = SK_ScalarMax;
|
||||
double fDescent = SK_ScalarMax;
|
||||
double fDescent = SK_ScalarMin;
|
||||
double fUnscaledAscent = SK_ScalarMax;
|
||||
// Total height of the paragraph including the current line.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user