Take pixel ratio into account for text stroke

This commit is contained in:
Andreas Hocevar
2017-10-09 18:45:55 +02:00
committed by Tim Schaub
parent 90b08cdc1c
commit 84f083af86
3 changed files with 9 additions and 3 deletions

View File

@@ -326,7 +326,7 @@ ol.render.canvas.TextReplay.prototype.getImage_ = function(text, fill, stroke) {
context.font = textState.font;
if (stroke) {
context.strokeStyle = strokeState.strokeStyle;
context.lineWidth = strokeState.lineWidth;
context.lineWidth = strokeWidth * pixelRatio;
context.lineCap = strokeState.lineCap;
context.lineJoin = strokeState.lineJoin;
context.miterLimit = strokeState.miterLimit;

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -17,14 +17,14 @@ describe('ol.rendering.style.Text', function() {
var map, vectorSource;
function createMap(renderer) {
function createMap(renderer, opt_pixelRatio) {
vectorSource = new ol.source.Vector();
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
map = new ol.Map({
pixelRatio: 1,
pixelRatio: opt_pixelRatio || 1,
target: createMapDiv(200, 200),
renderer: renderer,
layers: [vectorLayer],
@@ -154,6 +154,12 @@ describe('ol.rendering.style.Text', function() {
expectResemble(map, 'rendering/ol/style/expected/text-rotated-canvas.png', IMAGE_TOLERANCE, done);
});
it('renders correct stroke with pixelRatio != 1', function(done) {
createMap('canvas', 2);
createFeatures();
expectResemble(map, 'rendering/ol/style/expected/text-canvas-hidpi.png', IMAGE_TOLERANCE, done);
});
it('renders multiline text with alignment options', function(done) {
createMap('canvas');
var feature;