Skip to content

Commit

Permalink
answers #42
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Aug 5, 2019
1 parent ed44a73 commit b449461
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ FVimFontAutohint v:true
FVimFontSubpixel v:true
FVimFontLcdRender v:true
FVimFontHintLevel 'full'
FVimFontLineHeight '+1.0' " can be 'default', '14.0', '-1.0' etc.
" Try to snap the fonts to the pixels, reduces blur
" in some situations (e.g. 100% DPI).
Expand Down
2 changes: 2 additions & 0 deletions ViewModels/EditorViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ type EditorViewModel(GridId: int, ?parent: EditorViewModel, ?_gridsize: GridSize
hlchangeEvent.Publish
|> Observable.throttle(TimeSpan.FromMilliseconds 100.0)
|> Observable.subscribe (fun () -> markAllDirty())

States.Register.Watch "font" (fun () -> fontConfig())
]

member __.Item with get(row, col) = grid_buffer.[row, col]
Expand Down
2 changes: 2 additions & 0 deletions neovim/neovim.model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ let Start opts =
States.Register.Prop<SKPaintHinting> States.parseHintLevel "font.hintLevel"
States.Register.Prop<SKFontStyleWeight> States.parseFontWeight "font.weight.normal"
States.Register.Prop<SKFontStyleWeight> States.parseFontWeight "font.weight.bold"
States.Register.Prop<States.LineHeightOption> States.parseLineHeightOption "font.lineheight"
States.Register.Bool "cursor.smoothblink"
States.Register.Bool "cursor.smoothmove"
ignore(States.Register.Notify "remote.detach" (fun _ -> Detach()))
Expand Down Expand Up @@ -377,6 +378,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 FVimFontLineHeight" 1 (sprintf "call rpcnotify(%d, 'font.lineheight', <args>)" 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.drawBounds', <args>)" myChannel))
Expand Down
19 changes: 19 additions & 0 deletions states.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ let getNotificationEvent eventName =
notificationEvents.[eventName] <- ev
ev

type LineHeightOption =
| Absolute of float
| Add of float
| Default

// cursor
let mutable cursor_smoothmove = false
let mutable cursor_smoothblink = false
Expand All @@ -54,6 +59,7 @@ let mutable font_autosnap = true
let mutable font_hintLevel = SKPaintHinting.NoHinting
let mutable font_weight_normal = SKFontStyleWeight.Normal
let mutable font_weight_bold = SKFontStyleWeight.Bold
let mutable font_lineheight = LineHeightOption.Default

module private Helper =
type Foo = A
Expand Down Expand Up @@ -83,6 +89,19 @@ let parseFontWeight (v: obj) =
| Integer32 v -> Some(LanguagePrimitives.EnumOfValue v)
| _ -> None

let parseLineHeightOption (v: obj) =
match v with
| String v ->
if v.StartsWith("+") then
Some(Add(float v.[1..]))
elif v.StartsWith("-") then
Some(Add(-float v.[1..]))
elif v.ToLowerInvariant() = "default" then
Some Default
else
Some(Absolute(float v))
| _ -> None

let Shutdown code = _appLifetime.Shutdown code
let SetTitle title = _appLifetime.MainWindow.Title <- title

Expand Down
9 changes: 7 additions & 2 deletions ui.fs
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,17 @@ module ui =
paint.TextSize <- single s'

let w' = float(paint.MeasureText str)
let h' = round(float(paint.FontSpacing) * scaling) / scaling
let h'' =
match States.font_lineheight with
| States.Absolute h' -> h'
| States.Default -> float paint.FontSpacing
| States.Add h' -> (float paint.FontSpacing) + h'
let h' = round(h'' * scaling) / scaling

// calculate score
let score' =
abs(w' * scaling - round(w' * scaling)) +
abs(h' * scaling - round(float(paint.FontSpacing) * scaling))
abs(h' * scaling - round(h'' * scaling))

if score' < score then
score <- score'
Expand Down

0 comments on commit b449461

Please sign in to comment.