Skip to content

Commit

Permalink
improved textAnchor placement
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Deubler <[email protected]>
  • Loading branch information
TerminalTim committed Oct 26, 2023
1 parent 9ddbdcd commit 5c62043
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/display/src/displays/webgl/buffer/addText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import {TextStyle} from '@here/xyz-maps-core';
const EXTENT_SCALE = 64;

const ANCHOR_OFFSET: Record<TextStyle['textAnchor'], { x: number, y: number }> = {
Center: {x: .5, y: 1},
Left: {x: 0, y: 1},
Right: {x: 1, y: 1},
Top: {x: .5, y: 0},
TopLeft: {x: 0, y: 0},
TopRight: {x: 1, y: 0},
Bottom: {x: .5, y: 2},
BottomLeft: {x: 0, y: 2},
BottomRight: {x: 1, y: 2}
Center: {x: .5, y: 0},
Left: {x: 0, y: 0},
Right: {x: 1, y: 0},
Top: {x: .5, y: -1},
TopLeft: {x: 0., y: -1},
TopRight: {x: 1, y: -1},
Bottom: {x: .5, y: 1},
BottomLeft: {x: 0, y: 1},
BottomRight: {x: 1, y: 1}
};

const addText = (
Expand All @@ -52,7 +52,10 @@ const addText = (
const lineOffset = lines.length - 1;
const lineHeight = glyphAtlas.lineHeight;
const anchorOffset = ANCHOR_OFFSET[textAnchor] || ANCHOR_OFFSET.Center;
let ty = (glyphAtlas.baselineOffset + lineHeight * lineOffset * .5) * OFFSET_SCALE * anchorOffset.y;
// let ty = glyphAtlas.baselineOffset + lineHeight * lineOffset * .5;
// ty += lineHeight * lines.length * anchorOffset.y * .5;
let ty = glyphAtlas.baselineOffset + 0.5 * lineHeight * (lineOffset + lines.length * anchorOffset.y);
ty *= OFFSET_SCALE;

// LSB defines visibility, visible by default
cx = cx * EXTENT_SCALE << 1 | 1;
Expand Down

0 comments on commit 5c62043

Please sign in to comment.