Skip to content

Commit

Permalink
Rename Canvas2D.textLetterSpacing to Canvas2D.letterSpacing
Browse files Browse the repository at this point in the history
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056509
Commit-Queue: Yi Xu <[email protected]>
Reviewed-by: Bo <[email protected]>
Reviewed-by: Aaron Krajeski <[email protected]>
Cr-Commit-Position: refs/heads/master@{#906594}
  • Loading branch information
yiyix authored and Chromium LUCI CQ committed Jul 29, 2021
1 parent 97267be commit c99f03c
Show file tree
Hide file tree
Showing 29 changed files with 120 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ interface CanvasRenderingContext2D
getter globalCompositeOperation
getter imageSmoothingEnabled
getter imageSmoothingQuality
getter letterSpacing
getter lineCap
getter lineDashOffset
getter lineJoin
Expand All @@ -702,7 +703,6 @@ interface CanvasRenderingContext2D
getter strokeStyle
getter textAlign
getter textBaseline
getter textLetterSpacing
getter textRendering
getter wordSpacing
method arc
Expand Down Expand Up @@ -759,6 +759,7 @@ interface CanvasRenderingContext2D
setter globalCompositeOperation
setter imageSmoothingEnabled
setter imageSmoothingQuality
setter letterSpacing
setter lineCap
setter lineDashOffset
setter lineJoin
Expand All @@ -771,7 +772,6 @@ interface CanvasRenderingContext2D
setter strokeStyle
setter textAlign
setter textBaseline
setter textLetterSpacing
setter textRendering
setter wordSpacing
interface ChannelMergerNode : AudioNode
Expand Down Expand Up @@ -4249,6 +4249,7 @@ interface OffscreenCanvasRenderingContext2D
getter globalCompositeOperation
getter imageSmoothingEnabled
getter imageSmoothingQuality
getter letterSpacing
getter lineCap
getter lineDashOffset
getter lineJoin
Expand All @@ -4260,7 +4261,6 @@ interface OffscreenCanvasRenderingContext2D
getter shadowOffsetY
getter strokeStyle
getter textAlign
getter textLetterSpacing
getter textRendering
getter wordSpacing
getter textBaseline
Expand Down Expand Up @@ -4316,6 +4316,7 @@ interface OffscreenCanvasRenderingContext2D
setter globalCompositeOperation
setter imageSmoothingEnabled
setter imageSmoothingQuality
setter letterSpacing
setter lineCap
setter lineDashOffset
setter lineJoin
Expand All @@ -4328,7 +4329,6 @@ interface OffscreenCanvasRenderingContext2D
setter strokeStyle
setter textAlign
setter textBaseline
setter textLetterSpacing
setter textRendering
setter wordSpacing
interface Option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2404,8 +2404,8 @@ void BaseRenderingContext2D::CheckOverdraw(
WillOverwriteCanvas();
}

double BaseRenderingContext2D::textLetterSpacing() const {
return GetState().GetTextLetterSpacing();
double BaseRenderingContext2D::letterSpacing() const {
return GetState().GetLetterSpacing();
}

double BaseRenderingContext2D::wordSpacing() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
String textBaseline() const;
void setTextBaseline(const String&);

double textLetterSpacing() const;
double letterSpacing() const;
double wordSpacing() const;
String textRendering() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,17 +785,15 @@ void CanvasRenderingContext2D::setDirection(const String& direction_string) {
GetState().SetDirection(direction);
}

void CanvasRenderingContext2D::setTextLetterSpacing(
const double letter_spacing) {
void CanvasRenderingContext2D::setLetterSpacing(const double letter_spacing) {
if (UNLIKELY(!std::isfinite(letter_spacing)))
return;

if (!GetState().HasRealizedFont())
setFont(font());

float letter_spacing_float = clampTo<float>(letter_spacing);
GetState().SetTextLetterSpacing(letter_spacing_float,
Host()->GetFontSelector());
GetState().SetLetterSpacing(letter_spacing_float, Host()->GetFontSelector());
}

void CanvasRenderingContext2D::setWordSpacing(const double word_spacing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class MODULES_EXPORT CanvasRenderingContext2D final
String direction() const;
void setDirection(const String&);

void setTextLetterSpacing(const double letter_spacing);
void setLetterSpacing(const double letter_spacing);
void setWordSpacing(const double word_spacing);
void setTextRendering(const String&);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ interface CanvasRenderingContext2D {
[RuntimeEnabled=NewCanvas2DAPI] attribute DOMString fontKerning; // "auto", "normal", "none" (default: "auto")
[RuntimeEnabled=NewCanvas2DAPI] attribute DOMString fontStretch; // "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "normal", "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" (default: normal)
[RuntimeEnabled=NewCanvas2DAPI] attribute DOMString fontVariantCaps; // "normal", "small-caps", "all-small-caps", "petite-caps", "all-petite-caps", "unicase", "titling-caps" (default: "normal")
[RuntimeEnabled=NewCanvas2DAPI] attribute unrestricted double textLetterSpacing; // length in pixel (default: 0)
[RuntimeEnabled=NewCanvas2DAPI] attribute unrestricted double letterSpacing; // length in pixel (default: 0)
[RuntimeEnabled=NewCanvas2DAPI] attribute DOMString textRendering; // "auto", "optimizeSpeed", "optimizeLegibility", "geometricPrecision" (default: auto)
[RuntimeEnabled=NewCanvas2DAPI] attribute unrestricted double wordSpacing; // length in pixel (default: 0)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,8 @@ bool CanvasRenderingContext2DState::PatternIsAccelerated(
return Style(paint_type)->GetCanvasPattern()->GetPattern()->IsTextureBacked();
}

void CanvasRenderingContext2DState::SetTextLetterSpacing(
float letter_spacing,
FontSelector* selector) {
void CanvasRenderingContext2DState::SetLetterSpacing(float letter_spacing,
FontSelector* selector) {
DCHECK(realized_font_);
FontDescription font_description(GetFontDescription());
font_description.SetLetterSpacing(letter_spacing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ class CanvasRenderingContext2DState final
void SetTextBaseline(TextBaseline baseline) { text_baseline_ = baseline; }
TextBaseline GetTextBaseline() const { return text_baseline_; }

void SetTextLetterSpacing(float letter_space, FontSelector* selector);
float GetTextLetterSpacing() const { return letter_spacing_; }
void SetLetterSpacing(float letter_space, FontSelector* selector);
float GetLetterSpacing() const { return letter_spacing_; }

void SetWordSpacing(float word_space, FontSelector* selector);
float GetWordSpacing() const { return word_spacing_; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ String OffscreenCanvasRenderingContext2D::direction() const {
? kRtlDirectionString
: kLtrDirectionString;
}
void OffscreenCanvasRenderingContext2D::setTextLetterSpacing(
void OffscreenCanvasRenderingContext2D::setLetterSpacing(
const double letter_spacing) {
if (UNLIKELY(!std::isfinite(letter_spacing)))
return;
Expand All @@ -482,8 +482,7 @@ void OffscreenCanvasRenderingContext2D::setTextLetterSpacing(
setFont(font());

float letter_spacing_float = clampTo<float>(letter_spacing);
GetState().SetTextLetterSpacing(letter_spacing_float,
Host()->GetFontSelector());
GetState().SetLetterSpacing(letter_spacing_float, Host()->GetFontSelector());
}

void OffscreenCanvasRenderingContext2D::setWordSpacing(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MODULES_EXPORT OffscreenCanvasRenderingContext2D final
String direction() const;
void setDirection(const String&);

void setTextLetterSpacing(const double letter_spacing);
void setLetterSpacing(const double letter_spacing);
void setWordSpacing(const double word_spacing);
void setTextRendering(const String&);
void setFontKerning(const String&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
[RuntimeEnabled=NewCanvas2DAPI] attribute DOMString fontKerning; // "auto", "normal", "none" (default: "auto")
[RuntimeEnabled=NewCanvas2DAPI] attribute DOMString fontStretch; // "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "normal", "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" (default: normal)
[RuntimeEnabled=NewCanvas2DAPI] attribute DOMString fontVariantCaps; // "normal", "small-caps", "all-small-caps", "petite-caps", "all-petite-caps", "unicase", "titling-caps" (default: "normal")
[RuntimeEnabled=NewCanvas2DAPI] attribute unrestricted double textLetterSpacing; // length in pixel (default: 0)
[RuntimeEnabled=NewCanvas2DAPI] attribute unrestricted double letterSpacing; // length in pixel (default: 0)
[RuntimeEnabled=NewCanvas2DAPI] attribute DOMString textRendering; // "auto", "optimizeSpeed", "optimizeLegibility", "geometricPrecision" (default: auto)
[RuntimeEnabled=NewCanvas2DAPI] attribute unrestricted double wordSpacing; // length in pixel (default: 0)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ <h1>2d.text.drawing.style.nonfinite.spacing</h1>
var t = async_test("Testing letter spacing and word spacing with nonfinite inputs");
_addTest(function(canvas, ctx) {

_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");

function test_word_spacing(value) {
ctx.wordSpacing = value;
ctx.textLetterSpacing = value;
ctx.letterSpacing = value;
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");
_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
}
test_word_spacing(NaN);
test_word_spacing(Infinity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ <h1>2d.text.drawing.style.spacing</h1>
var t = async_test("Testing letter spacing and word spacing");
_addTest(function(canvas, ctx) {

_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");

ctx.textLetterSpacing = 3;
_assertSame(ctx.textLetterSpacing, 3, "ctx.textLetterSpacing", "3");
ctx.letterSpacing = 3;
_assertSame(ctx.letterSpacing, 3, "ctx.letterSpacing", "3");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");

ctx.wordSpacing = 5;
_assertSame(ctx.textLetterSpacing, 3, "ctx.textLetterSpacing", "3");
_assertSame(ctx.letterSpacing, 3, "ctx.letterSpacing", "3");
_assertSame(ctx.wordSpacing, 5, "ctx.wordSpacing", "5");

ctx.textLetterSpacing = -1;
ctx.letterSpacing = -1;
ctx.wordSpacing = -1;
_assertSame(ctx.textLetterSpacing, -1, "ctx.textLetterSpacing", "-1");
_assertSame(ctx.letterSpacing, -1, "ctx.letterSpacing", "-1");
_assertSame(ctx.wordSpacing, -1, "ctx.wordSpacing", "-1");


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ <h1>2d.text.drawing.style.spacing.measure</h1>
var t = async_test("Testing letter spacing and word spacing");
_addTest(function(canvas, ctx) {

_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");
var width_normal = ctx.measureText('Hello World').width;

ctx.textLetterSpacing = 3;
_assertSame(ctx.textLetterSpacing, 3, "ctx.textLetterSpacing", "3");
ctx.letterSpacing = 3;
_assertSame(ctx.letterSpacing, 3, "ctx.letterSpacing", "3");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");
var width_with_spacing = ctx.measureText('Hello World').width;
// Add letter spacing after each letter, so 11 * 3 = 33px longer.
_assertSame(width_with_spacing, width_normal + 33, "width_with_spacing", "width_normal + 33");

ctx.wordSpacing = 5;
ctx.textLetterSpacing = 0;
_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
ctx.letterSpacing = 0;
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 5, "ctx.wordSpacing", "5");
// Add Word Spacing between "Hello" and "World", so it's 5px longer.
width_with_spacing = ctx.measureText('Hello World').width;
_assertSame(width_with_spacing, width_normal + 5, "width_with_spacing", "width_normal + 5");

ctx.textLetterSpacing = -2;
ctx.letterSpacing = -2;
ctx.wordSpacing = -1;
_assertSame(ctx.textLetterSpacing, -2, "ctx.textLetterSpacing", "-2");
_assertSame(ctx.letterSpacing, -2, "ctx.letterSpacing", "-2");
_assertSame(ctx.wordSpacing, -1, "ctx.wordSpacing", "-1");
// Add Word Spacing and letter spacing, so it's -11*2 = -22px from
// letter spacing and -1px from word spacing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ <h1>2d.text.drawing.style.nonfinite.spacing</h1>
var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");

function test_word_spacing(value) {
ctx.wordSpacing = value;
ctx.textLetterSpacing = value;
ctx.letterSpacing = value;
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");
_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
}
test_word_spacing(NaN);
test_word_spacing(Infinity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ t.step(function() {
var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");

function test_word_spacing(value) {
ctx.wordSpacing = value;
ctx.textLetterSpacing = value;
ctx.letterSpacing = value;
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");
_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
}
test_word_spacing(NaN);
test_word_spacing(Infinity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ <h1>2d.text.drawing.style.spacing</h1>
var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");

ctx.textLetterSpacing = 3;
_assertSame(ctx.textLetterSpacing, 3, "ctx.textLetterSpacing", "3");
ctx.letterSpacing = 3;
_assertSame(ctx.letterSpacing, 3, "ctx.letterSpacing", "3");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");

ctx.wordSpacing = 5;
_assertSame(ctx.textLetterSpacing, 3, "ctx.textLetterSpacing", "3");
_assertSame(ctx.letterSpacing, 3, "ctx.letterSpacing", "3");
_assertSame(ctx.wordSpacing, 5, "ctx.wordSpacing", "5");

ctx.textLetterSpacing = -1;
ctx.letterSpacing = -1;
ctx.wordSpacing = -1;
_assertSame(ctx.textLetterSpacing, -1, "ctx.textLetterSpacing", "-1");
_assertSame(ctx.letterSpacing, -1, "ctx.letterSpacing", "-1");
_assertSame(ctx.wordSpacing, -1, "ctx.wordSpacing", "-1");
t.done();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ <h1>2d.text.drawing.style.spacing.measure</h1>
var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");
var width_normal = ctx.measureText('Hello World').width;

ctx.textLetterSpacing = 3;
_assertSame(ctx.textLetterSpacing, 3, "ctx.textLetterSpacing", "3");
ctx.letterSpacing = 3;
_assertSame(ctx.letterSpacing, 3, "ctx.letterSpacing", "3");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");
var width_with_spacing = ctx.measureText('Hello World').width;
// Add letter spacing after each letter, so 11 * 3 = 33px longer.
_assertSame(width_with_spacing, width_normal + 33, "width_with_spacing", "width_normal + 33");

ctx.wordSpacing = 5;
ctx.textLetterSpacing = 0;
_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
ctx.letterSpacing = 0;
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 5, "ctx.wordSpacing", "5");
// Add Word Spacing between "Hello" and "World", so it's 5px longer.
width_with_spacing = ctx.measureText('Hello World').width;
_assertSame(width_with_spacing, width_normal + 5, "width_with_spacing", "width_normal + 5");

ctx.textLetterSpacing = -2;
ctx.letterSpacing = -2;
ctx.wordSpacing = -1;
_assertSame(ctx.textLetterSpacing, -2, "ctx.textLetterSpacing", "-2");
_assertSame(ctx.letterSpacing, -2, "ctx.letterSpacing", "-2");
_assertSame(ctx.wordSpacing, -1, "ctx.wordSpacing", "-1");
// Add Word Spacing and letter spacing, so it's -11*2 = -22px from
// letter spacing and -1px from word spacing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ t.step(function() {
var offscreenCanvas = new OffscreenCanvas(100, 50);
var ctx = offscreenCanvas.getContext('2d');

_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");
var width_normal = ctx.measureText('Hello World').width;

ctx.textLetterSpacing = 3;
_assertSame(ctx.textLetterSpacing, 3, "ctx.textLetterSpacing", "3");
ctx.letterSpacing = 3;
_assertSame(ctx.letterSpacing, 3, "ctx.letterSpacing", "3");
_assertSame(ctx.wordSpacing, 0, "ctx.wordSpacing", "0");
var width_with_spacing = ctx.measureText('Hello World').width;
// Add letter spacing after each letter, so 11 * 3 = 33px longer.
_assertSame(width_with_spacing, width_normal + 33, "width_with_spacing", "width_normal + 33");

ctx.wordSpacing = 5;
ctx.textLetterSpacing = 0;
_assertSame(ctx.textLetterSpacing, 0, "ctx.textLetterSpacing", "0");
ctx.letterSpacing = 0;
_assertSame(ctx.letterSpacing, 0, "ctx.letterSpacing", "0");
_assertSame(ctx.wordSpacing, 5, "ctx.wordSpacing", "5");
// Add Word Spacing between "Hello" and "World", so it's 5px longer.
width_with_spacing = ctx.measureText('Hello World').width;
_assertSame(width_with_spacing, width_normal + 5, "width_with_spacing", "width_normal + 5");

ctx.textLetterSpacing = -2;
ctx.letterSpacing = -2;
ctx.wordSpacing = -1;
_assertSame(ctx.textLetterSpacing, -2, "ctx.textLetterSpacing", "-2");
_assertSame(ctx.letterSpacing, -2, "ctx.letterSpacing", "-2");
_assertSame(ctx.wordSpacing, -1, "ctx.wordSpacing", "-1");
// Add Word Spacing and letter spacing, so it's -11*2 = -22px from
// letter spacing and -1px from word spacing.
Expand Down
Loading

0 comments on commit c99f03c

Please sign in to comment.