🐛 Measure latin chars with subpixel font scaling

This commit is contained in:
Antonio Scandurra
2015-10-15 18:49:54 +02:00
parent 43229a1b9e
commit abf306943a
3 changed files with 8 additions and 12 deletions

View File

@@ -2893,12 +2893,12 @@ describe "TextEditorComponent", ->
describe "when changing the font", ->
it "measures the default char width and the double width char width", ->
expect(editor.getDefaultCharWidth()).toBe(12)
expect(editor.getDefaultCharWidth()).toBeCloseTo(12, 0)
component.setFontSize(10)
nextAnimationFrame()
expect(editor.getDefaultCharWidth()).toBe(6)
expect(editor.getDefaultCharWidth()).toBeCloseTo(6, 0)
expect(editor.getDoubleWidthCharWidth()).toBe(10)
describe "hiding and showing the editor", ->

View File

@@ -266,7 +266,7 @@ class DisplayBuffer extends Model
@getEditorWidthInChars()
getSoftWrapColumnForTokenizedLine: (tokenizedLine) ->
lineMaxWidth = Math.round(@getSoftWrapColumn() * @getDefaultCharWidth())
lineMaxWidth = @getSoftWrapColumn() * @getDefaultCharWidth()
iterator = tokenizedLine.getTokenIterator()
column = 0
currentWidth = 0

View File

@@ -7,7 +7,9 @@ DummyLineNode.className = 'line'
DummyLineNode.style.position = 'absolute'
DummyLineNode.style.visibility = 'hidden'
DummyLineNode.appendChild(document.createElement('span'))
DummyLineNode.firstChild.textContent = 'xフ'
DummyLineNode.appendChild(document.createElement('span'))
DummyLineNode.children[0].textContent = 'x'
DummyLineNode.children[1].textContent = ''
RangeForMeasurement = document.createRange()
@@ -81,14 +83,8 @@ class LinesComponent extends TiledComponent
textNode = DummyLineNode.firstChild.childNodes[0]
lineHeightInPixels = DummyLineNode.getBoundingClientRect().height
RangeForMeasurement.setStart(textNode, 0)
RangeForMeasurement.setEnd(textNode, 1)
defaultCharWidth = RangeForMeasurement.getBoundingClientRect().width
RangeForMeasurement.setStart(textNode, 1)
RangeForMeasurement.setEnd(textNode, 2)
doubleWidthCharWidth = RangeForMeasurement.getBoundingClientRect().width
defaultCharWidth = DummyLineNode.children[0].getBoundingClientRect().width
doubleWidthCharWidth = DummyLineNode.children[1].getBoundingClientRect().width
@domNode.removeChild(DummyLineNode)