Skip to content

Commit

Permalink
Take into account image padding and image pixel ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshalamov committed Nov 18, 2019
1 parent aad7dea commit ad496b2
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/render/image_atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type ImageManager from './image_manager';
import type Texture from './texture';

const IMAGE_PADDING = 1;
export {IMAGE_PADDING};

type Rect = {
x: number,
Expand Down
5 changes: 3 additions & 2 deletions src/symbol/quads.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {GLYPH_PBF_BORDER} from '../style/parse_glyph_pbf';
import type Anchor from './anchor';
import type {PositionedIcon, Shaping} from './shaping';
import {SHAPING_DEFAULT_OFFSET} from './shaping';
import {IMAGE_PADDING} from '../render/image_atlas';
import type SymbolStyleLayer from '../style/style_layer/symbol_style_layer';
import type {Feature} from '../style-spec/expression';
import type {StyleImage} from '../style/style_image';
Expand Down Expand Up @@ -55,7 +56,7 @@ export function getIconQuads(
// If you have a 10px icon that isn't perfectly aligned to the pixel grid it will cover 11 actual
// pixels. The quad needs to be padded to account for this, otherwise they'll look slightly clipped
// on one edge in some cases.
const border = 1;
const border = IMAGE_PADDING;

// Expand the box to respect the 1 pixel border in the atlas image. We're using `image.paddedRect - border`
// instead of image.displaySize because we only pad with one pixel for retina images as well, and the
Expand Down Expand Up @@ -134,7 +135,7 @@ export function getGlyphQuads(anchor: Anchor,
const image = imageMap[positionedGlyph.imageName];
isSDF = image.sdf;
pixelRatio = image.pixelRatio;
rectBuffer = 0.0;
rectBuffer = IMAGE_PADDING / pixelRatio;
}

const glyphOffset = alongLine ?
Expand Down
3 changes: 2 additions & 1 deletion src/symbol/shaping.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {warnOnce} from '../util/util';
import type {StyleGlyph, GlyphMetrics} from '../style/style_glyph';
import {GLYPH_PBF_BORDER} from '../style/parse_glyph_pbf';
import type {ImagePosition} from '../render/image_atlas';
import {IMAGE_PADDING} from '../render/image_atlas';
import type {Rect, GlyphPosition} from '../render/glyph_atlas';
import Formatted, {FormattedSection} from '../style-spec/expression/types/formatted';

Expand Down Expand Up @@ -638,7 +639,7 @@ function shapeLines(shaping: Shaping,

metrics = {width: size[0],
height: size[1],
left: 0,
left: IMAGE_PADDING,
top: -GLYPH_PBF_BORDER,
advance: vertical ? size[1] : size[0]};

Expand Down
8 changes: 4 additions & 4 deletions test/expected/text-shaping-images-horizontal.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"metrics": {
"width": 14,
"height": 14,
"left": 0,
"left": 1,
"top": -3,
"advance": 14
},
Expand All @@ -106,7 +106,7 @@
"metrics": {
"width": 30,
"height": 14,
"left": 0,
"left": 1,
"top": -3,
"advance": 30
},
Expand Down Expand Up @@ -134,7 +134,7 @@
"metrics": {
"width": 14,
"height": 30,
"left": 0,
"left": 1,
"top": -3,
"advance": 14
},
Expand All @@ -157,7 +157,7 @@
"metrics": {
"width": 14,
"height": 14,
"left": 0,
"left": 1,
"top": -3,
"advance": 14
},
Expand Down
8 changes: 4 additions & 4 deletions test/expected/text-shaping-images-vertical.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"metrics": {
"width": 14,
"height": 14,
"left": 0,
"left": 1,
"top": -3,
"advance": 14
},
Expand All @@ -60,7 +60,7 @@
"metrics": {
"width": 30,
"height": 14,
"left": 0,
"left": 1,
"top": -3,
"advance": 14
},
Expand Down Expand Up @@ -88,7 +88,7 @@
"metrics": {
"width": 14,
"height": 30,
"left": 0,
"left": 1,
"top": -3,
"advance": 30
},
Expand All @@ -111,7 +111,7 @@
"metrics": {
"width": 14,
"height": 14,
"left": 0,
"left": 1,
"top": -3,
"advance": 14
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ad496b2

Please sign in to comment.