Skip to content

Commit

Permalink
snap to device pixels (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Jul 23, 2019
1 parent 575ffd0 commit af08d67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ViewModels/EditorViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ type EditorViewModel(GridId: int, ?parent: EditorViewModel, ?_gridsize: GridSize
// It turns out the space " " advances farest...
// So we measure it as the width.
let w, h = MeasureText(" ", _guifont, _guifontwide, font_size)
let _s = Point(float w, float h)
// Snap to device pixels
let _s = Point(float w, floor(float h * grid_scale)/grid_scale)
glyph_size <- Size(_s.X, _s.Y)
trace "fontConfig: guifont=%s guifontwide=%s size=%A" _guifont _guifontwide glyph_size
this.cursorConfig()
Expand Down
5 changes: 4 additions & 1 deletion ui.fs
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,17 @@ module ui =
()

let RenderText (ctx: IDrawingContextImpl, region: Rect, scale: float, fg: SKPaint, bg: SKPaint, sp: SKPaint, underline: bool, undercurl: bool, text: string, useShaping: bool) =

// DrawText accepts the coordinate of the baseline.
// h = [padding space 1] + above baseline | below baseline + [padding space 2]
let h = region.Bottom - region.Y
// total_padding = padding space 1 + padding space 2
let total_padding = h - ((float fg.FontMetrics.Bottom - float fg.FontMetrics.Top) )
let baseline = region.Y + (total_padding / 2.0) - (float fg.FontMetrics.Top )
let snappedBaseline = ceil(baseline * scale) / scale
let region = region.WithY(region.Y + snappedBaseline - baseline)
(*printfn "scale=%A pad=%A base=%A region=%A" scale total_padding baseline region*)
let fontPos = Point(region.X, baseline)
let fontPos = Point(region.X, snappedBaseline)

let skia = ctx :?> ISkiaDrawingContextImpl

Expand Down

0 comments on commit af08d67

Please sign in to comment.