зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1777671 - Account for glyph orientations when returning rotation of character r=jfkthame
Differential Revision: https://phabricator.services.mozilla.com/D150858
This commit is contained in:
Родитель
ddd50edc4b
Коммит
4bcc81eaf7
|
@ -513,6 +513,16 @@ class gfxTextRun : public gfxShapedText {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsSidewaysLeft() const {
|
||||
return (mOrientation & mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_MASK) ==
|
||||
mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT;
|
||||
}
|
||||
|
||||
bool IsSidewaysRight() const {
|
||||
return (mOrientation & mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_MASK) ==
|
||||
mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT;
|
||||
}
|
||||
};
|
||||
|
||||
// Script run codes that we will mark as CJK to suppress skip-ink behavior.
|
||||
|
|
|
@ -2034,6 +2034,11 @@ class CharIterator {
|
|||
*/
|
||||
bool IsClusterAndLigatureGroupStart() const;
|
||||
|
||||
/**
|
||||
* Returns the glyph run for the current character.
|
||||
*/
|
||||
const gfxTextRun::GlyphRun& GlyphRun() const;
|
||||
|
||||
/**
|
||||
* Returns whether the current character is trimmed away when painting,
|
||||
* due to it being leading/trailing white space.
|
||||
|
@ -2281,6 +2286,15 @@ bool CharIterator::IsClusterAndLigatureGroupStart() const {
|
|||
mTextRun->IsClusterStart(mSkipCharsIterator.GetSkippedOffset());
|
||||
}
|
||||
|
||||
const gfxTextRun::GlyphRun& CharIterator::GlyphRun() const {
|
||||
uint32_t numRuns;
|
||||
const gfxTextRun::GlyphRun* glyphRuns = mTextRun->GetGlyphRuns(&numRuns);
|
||||
uint32_t runIndex = mTextRun->FindFirstGlyphRunContaining(
|
||||
mSkipCharsIterator.GetSkippedOffset());
|
||||
MOZ_ASSERT(runIndex < numRuns);
|
||||
return glyphRuns[runIndex];
|
||||
}
|
||||
|
||||
bool CharIterator::IsOriginalCharTrimmed() const {
|
||||
if (mFrameForTrimCheck != TextFrame()) {
|
||||
// Since we do a lot of trim checking, we cache the trimmed offsets and
|
||||
|
@ -4025,7 +4039,13 @@ float SVGTextFrame::GetRotationOfChar(nsIContent* aContent, uint32_t aCharNum,
|
|||
return 0;
|
||||
}
|
||||
|
||||
return mPositions[it.TextElementCharIndex()].mAngle * 180.0 / M_PI;
|
||||
// we need to account for the glyph's underlying orientation
|
||||
const gfxTextRun::GlyphRun& glyphRun = it.GlyphRun();
|
||||
int32_t glyphOrientation =
|
||||
90 * (glyphRun.IsSidewaysRight() - glyphRun.IsSidewaysLeft());
|
||||
|
||||
return mPositions[it.TextElementCharIndex()].mAngle * 180.0 / M_PI +
|
||||
glyphOrientation;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
[getrotationofchar.html]
|
||||
['text-orientation: mixed' - vertical-rl]
|
||||
expected: FAIL
|
||||
|
||||
['text-orientation: sideways' - vertical-rl]
|
||||
expected: FAIL
|
||||
|
||||
[Rotation attribute - vertical-rl]
|
||||
expected: FAIL
|
||||
|
||||
[<textPath> - vertical-rl]
|
||||
expected: FAIL
|
||||
|
|
@ -29,38 +29,41 @@ function normalizedRotation(element, index) {
|
|||
}
|
||||
|
||||
const container = document.querySelector('#container');
|
||||
['horizontal-tb', 'vertical-rl'].forEach(mode => {
|
||||
['horizontal-tb', 'vertical-rl', 'vertical-lr', 'sideways-rl', 'sideways-lr'].forEach(mode => {
|
||||
const isHorizontal = mode == 'horizontal-tb';
|
||||
const isVertical = mode == 'vertical-rl' || mode == 'vertical-lr';
|
||||
const sidewaysDelta = 90 * ((mode == 'sideways-rl') - (mode == 'sideways-lr'));
|
||||
container.style.writingMode = mode;
|
||||
|
||||
test(() => {
|
||||
container.style.textOrientation = 'mixed';
|
||||
const element = container.appendChild(createSVGElement('text', {}, 'M月'));
|
||||
assert_equals(element.getRotationOfChar(0), isHorizontal ? 0 : 90, 'M');
|
||||
assert_equals(element.getRotationOfChar(1), 0, '月');
|
||||
const element = container.appendChild(createSVGElement('text', {}, ' M月X'));
|
||||
assert_equals(element.getRotationOfChar(0), isVertical ? 90 : sidewaysDelta, 'M');
|
||||
assert_equals(element.getRotationOfChar(1), sidewaysDelta, '月');
|
||||
assert_equals(element.getRotationOfChar(2), isVertical ? 90 : sidewaysDelta, 'X');
|
||||
}, `'text-orientation: mixed' - ${mode}`);
|
||||
|
||||
test(() => {
|
||||
container.style.textOrientation = 'upright';
|
||||
const element = container.appendChild(createSVGElement('text', {}, 'T火'));
|
||||
assert_equals(element.getRotationOfChar(0), 0, 'T');
|
||||
assert_equals(element.getRotationOfChar(1), 0, '火');
|
||||
assert_equals(element.getRotationOfChar(0), sidewaysDelta, 'T');
|
||||
assert_equals(element.getRotationOfChar(1), sidewaysDelta, '火');
|
||||
}, `'text-orientation: upright' - ${mode}`);
|
||||
|
||||
test(() => {
|
||||
container.style.textOrientation = 'sideways';
|
||||
const element = container.appendChild(createSVGElement('text', {}, 'W水'));
|
||||
assert_equals(element.getRotationOfChar(0), isHorizontal ? 0 : 90, 'W');
|
||||
assert_equals(element.getRotationOfChar(1), isHorizontal ? 0 : 90, '水');
|
||||
assert_equals(element.getRotationOfChar(0), isVertical ? 90 : sidewaysDelta, 'W');
|
||||
assert_equals(element.getRotationOfChar(1), isVertical ? 90 : sidewaysDelta, '水');
|
||||
}, `'text-orientation: sideways' - ${mode}`);
|
||||
|
||||
test(() => {
|
||||
container.style.textOrientation = 'mixed';
|
||||
const element = container.appendChild(
|
||||
createSVGElement('text', {rotate: '0 180.5 360 365 -10'}, 't木cde'));
|
||||
const shift = isHorizontal ? 0 : 90;
|
||||
const shift = isHorizontal ? 0 : 90 * (mode == 'sideways-rl' || isVertical) + 270 * (mode == 'sideways-lr');
|
||||
assert_equals(normalizedRotation(element, 0), 0 + shift, 't');
|
||||
assert_equals(normalizedRotation(element, 1), 180.5, '木');
|
||||
assert_equals(normalizedRotation(element, 1), 180.5 + sidewaysDelta, '木');
|
||||
assert_equals(normalizedRotation(element, 2), 0 + shift, 'c');
|
||||
assert_equals(normalizedRotation(element, 3), 5 + shift, 'd');
|
||||
assert_equals(normalizedRotation(element, 4), normalize(350 + shift), 'e');
|
||||
|
@ -72,9 +75,10 @@ const container = document.querySelector('#container');
|
|||
const element = container.appendChild(
|
||||
createSVGElement('text', {rotate: '0 0 25'},
|
||||
createSVGElement('textPath', {href: '#path1'}, 'F金r')));
|
||||
assert_equals(normalizedRotation(element, 0), 45, 'F');
|
||||
assert_equals(normalizedRotation(element, 1), isHorizontal ? 45 : 315, '金');
|
||||
assert_equals(normalizedRotation(element, 2), 45 + 25, 'r');
|
||||
const shift = (mode == 'sideways-lr') ? 180 : 0;
|
||||
assert_equals(normalizedRotation(element, 0), 45 + shift, 'F');
|
||||
assert_equals(normalizedRotation(element, 1), isVertical ? 315 : 45 + shift, '金');
|
||||
assert_equals(normalizedRotation(element, 2), 45 + 25 + shift, 'r');
|
||||
}, `<textPath> - ${mode}`);
|
||||
});
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче