Skip to content

Commit

Permalink
fix font-face, font-weight; bump 0.0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Nov 30, 2020
1 parent 33efce3 commit d584e7c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### Usage

```nim
requires "https://github.com/Quamolit/json-paint.nim#v0.0.18"
requires "https://github.com/Quamolit/json-paint.nim#v0.0.19"
```

```nim
Expand Down Expand Up @@ -64,7 +64,8 @@ x: 1
y: 1
text: 'DEMO'
'font-size': 14
'font-family': 'Arial'
'font-face': 'Arial'
'font-weight': 'normal',
color: Color
align: "center" # 'left' | 'center' | 'right'
```
Expand Down
2 changes: 1 addition & 1 deletion json_paint.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.0.18"
version = "0.0.19"
author = "jiyinyiyong"
description = "JSON DSL for canvas rendering"
license = "MIT"
Expand Down
7 changes: 5 additions & 2 deletions src/json_paint/shape_renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ proc renderText(ctx: ptr Context, tree: JsonNode, base: TreeContext) =
let fontSize = if tree.contains("font-size"): tree["font-size"].getFloat else: 14
let text = if tree.contains("text"): tree["text"].getStr else: "TEXT"
let align = if tree.contains("align"): tree["align"].getStr else: "left"
let fontFamily = if tree.contains("font-family"): tree["font-family"].getStr else: "Arial"
let fontFace = if tree.contains("font-face"): tree["font-face"].getStr else: "Arial"
let color = if tree.contains("color"): readJsonColor(tree["color"]) else: failedColor
ctx.selectFontFace text.cstring, FontSlantNormal, FontWeightNormal
var weight = FontWeightNormal
if tree.contains("font-weight") and tree["font-weight"].getStr() == "bold":
weight = FontWeightBold
ctx.selectFontFace fontFace.cstring, FontSlantNormal, weight
ctx.setFontSize fontSize
ctx.setSourceRgba(color.r, color.g, color.b, color.a)
var extents: TextExtents
Expand Down
2 changes: 2 additions & 0 deletions tests/demo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ proc renderSomething() =
"type": "text",
"text": "this is a demo",
"align": "center",
"font-face": "Menlo",
"font-weight": "normal",
"x": 40,
"y": 40,
"color": [140, 80, 76]
Expand Down

0 comments on commit d584e7c

Please sign in to comment.