Skip to content

Commit

Permalink
fix text-align; bump 0.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Nov 20, 2020
1 parent ed1de4d commit 8cc4bb1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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.12"
requires "https://github.com/Quamolit/json-paint.nim#v0.0.16"
```

```nim
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.15"
version = "0.0.16"
author = "jiyinyiyong"
description = "JSON DSL for canvas rendering"
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions src/json_paint.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ proc renderCanvas*(tree: JsonNode) =
let base = TreeContext(x: 0, y: 0)
resetTouchStack()
ctx.processJsonTree(tree, base)
ctx.destroy()

# cairo surface -> sdl serface -> sdl texture -> copy to render
var dataPtr = surface.getData()
Expand Down
4 changes: 2 additions & 2 deletions src/json_paint/shape_renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ proc renderText(ctx: ptr Context, tree: JsonNode, base: TreeContext) =
var extents: TextExtents
ctx.textExtents text.cstring, addr extents
var realX = x - extents.xBearing
case text
case align
of "center":
realX = x - extents.width / 2 - extents.xBearing
of "right":
realX = x - extents.width - extents.xBearing
of "left":
discard
else:
echo "unknown text align value: ", text
echo "WARNING: unknown align value " & align & ", expects left, center, right"
let realY = y - extents.height / 2 - extents.yBearing
ctx.moveTo realX, realY
ctx.showText text
Expand Down
2 changes: 1 addition & 1 deletion tests/demo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ proc renderSomething() =
{
"type": "text",
"text": "this is a demo",
"align": "left",
"align": "center",
"x": 40,
"y": 40,
"color": [140, 80, 76]
Expand Down

0 comments on commit 8cc4bb1

Please sign in to comment.