diff --git a/ViewModels/EditorViewModel.fs b/ViewModels/EditorViewModel.fs index 3e251e7..9807a69 100644 --- a/ViewModels/EditorViewModel.fs +++ b/ViewModels/EditorViewModel.fs @@ -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() diff --git a/ui.fs b/ui.fs index a7a6114..74ee5ea 100644 --- a/ui.fs +++ b/ui.fs @@ -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