Skip to content

Commit

Permalink
autosnap can be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Jul 29, 2019
1 parent f5c9a7f commit efbc6cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,22 @@ FVimDrawFPS v:true
" Font tweaks
FVimFontAntialias v:true
FVimFontDrawBounds v:true
FVimFontAutohint v:true
FVimFontSubpixel v:true
FVimFontLcdRender v:true
FVimFontHintLevel 'full'
" Try to snap the fonts to the pixels, reduces blur
" in some situations (e.g. 100% DPI).
FVimFontAutoSnap v:true
" Font weight tuning, possible valuaes are 100..900
FVimFontNormalWeight 400
FVimFontBoldWeight 700
" Font debugging -- draw bounds around each glyph
FVimFontDrawBounds v:true
" Detach from a remote session without killing the server
" If this command is executed on a standalone instance,
" the embedded process will be terminated anyway.
Expand Down
2 changes: 2 additions & 0 deletions neovim/neovim.model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ let Start opts =

// rpc handlers
List.iter ignore [
Notify "font.autosnap" (fun [| Bool(v) |] -> ui.autosnap <- v)
Notify "font.antialias" (fun [| Bool(v) |] -> ui.antialiased <- v)
Notify "font.bounds" (fun [| Bool(v) |] -> ui.drawBounds <- v)
Notify "font.autohint" (fun [| Bool(v) |] -> ui.autohint <- v)
Expand Down Expand Up @@ -424,6 +425,7 @@ let Start opts =
let! _ = Async.AwaitTask(nvim.``command!`` "-complete=expression FVimDrawFPS" 1 (sprintf "call rpcnotify(%d, 'DrawFPS', <args>)" myChannel))
let! _ = Async.AwaitTask(nvim.``command!`` "FVimDetach" 0 (sprintf "call rpcnotify(%d, 'remote.detach')" myChannel))

let! _ = Async.AwaitTask(nvim.``command!`` "-complete=expression FVimFontAutoSnap" 1 (sprintf "call rpcnotify(%d, 'font.autosnap', <args>)" myChannel))
let! _ = Async.AwaitTask(nvim.``command!`` "-complete=expression FVimFontAntialias" 1 (sprintf "call rpcnotify(%d, 'font.antialias', <args>)" myChannel))
let! _ = Async.AwaitTask(nvim.``command!`` "-complete=expression FVimFontDrawBounds" 1 (sprintf "call rpcnotify(%d, 'font.bounds', <args>)" myChannel))
let! _ = Async.AwaitTask(nvim.``command!`` "-complete=expression FVimFontAutohint" 1 (sprintf "call rpcnotify(%d, 'font.autohint', <args>)" myChannel))
Expand Down
8 changes: 6 additions & 2 deletions ui.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module ui =
let mutable autohint = false
let mutable subpixel = true
let mutable lcdrender = true
let mutable autosnap = true
let mutable hintLevel = SKPaintHinting.NoHinting
let mutable private normalWeight = SKFontStyleWeight.Normal
let mutable private boldWeight = SKFontStyleWeight.Bold
Expand Down Expand Up @@ -276,7 +277,7 @@ module ui =
let mutable w = 0.0
let mutable h = 0.0

for sizeStep = -50 to 50 do
let search (sizeStep: int) =
let s' = fontSize + float(sizeStep) * 0.01
paint.TextSize <- single s'

Expand All @@ -294,6 +295,9 @@ module ui =
h <- h'
s <- s'

if autosnap then [-50 .. 50] else [0]
|> List.iter search

s, w, h

let AllocateFramebuffer w h scale =
Expand Down Expand Up @@ -326,7 +330,7 @@ module ui =
// total_padding = padding space 1 + padding space 2
let total_padding = h - ((float fg.FontMetrics.Bottom - float fg.FontMetrics.Top) )
let baseline = region.Y + floor((total_padding / 2.0) - (float fg.FontMetrics.Top))
let snappedBaseline = ceil(baseline * scale) / scale
let snappedBaseline = floor(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, snappedBaseline)
Expand Down

0 comments on commit efbc6cb

Please sign in to comment.