Skip to content

Commit

Permalink
fix(troika-three-text): clipRect is no longer clamped to the text blo…
Browse files Browse the repository at this point in the history
…ck's bounds

If no clipRect is supplied, or the rect is larger than the block's
bounds, text is no longer clipped at the block's bounds. This allows
certain fonts with decorations that extend beyond the glyph box to show
their full shape.
  • Loading branch information
lojjic committed Oct 19, 2020
1 parent 596d8ca commit 15edbd9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/troika-three-text/src/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,16 @@ const Text = /*#__PURE__*/(() => {
uniforms.uTroikaUseGlyphColors.value = !!textInfo.glyphColors

let clipRect = this.clipRect
if (!(clipRect && Array.isArray(clipRect) && clipRect.length === 4)) {
uniforms.uTroikaClipRect.value.fromArray(totalBounds)
if (clipRect && Array.isArray(clipRect) && clipRect.length === 4) {
uniforms.uTroikaClipRect.value.fromArray(clipRect)
} else {
// no clipping - choose a finite rect that shouldn't ever be reached by overflowing glyphs or outlines
const pad = (this.fontSize || 0.1) * 100
uniforms.uTroikaClipRect.value.set(
Math.max(totalBounds[0], clipRect[0]),
Math.max(totalBounds[1], clipRect[1]),
Math.min(totalBounds[2], clipRect[2]),
Math.min(totalBounds[3], clipRect[3])
totalBounds[0] - pad,
totalBounds[1] - pad,
totalBounds[2] + pad,
totalBounds[3] + pad
)
}
this.geometry.applyClipRect(uniforms.uTroikaClipRect.value)
Expand Down

0 comments on commit 15edbd9

Please sign in to comment.