context miterLimit
This commit is contained in:
parent
2edcfac64f
commit
58ccbf025a
3 changed files with 18 additions and 7 deletions
|
@ -11,6 +11,7 @@ type
|
||||||
image*: Image
|
image*: Image
|
||||||
fillStyle*, strokeStyle*: Paint
|
fillStyle*, strokeStyle*: Paint
|
||||||
lineWidth*: float32
|
lineWidth*: float32
|
||||||
|
miterLimit*: float32
|
||||||
lineCap*: LineCap
|
lineCap*: LineCap
|
||||||
lineJoin*: LineJoin
|
lineJoin*: LineJoin
|
||||||
font*: Font
|
font*: Font
|
||||||
|
@ -24,6 +25,7 @@ type
|
||||||
ContextState = object
|
ContextState = object
|
||||||
fillStyle, strokeStyle: Paint
|
fillStyle, strokeStyle: Paint
|
||||||
lineWidth: float32
|
lineWidth: float32
|
||||||
|
miterLimit: float32
|
||||||
lineCap: LineCap
|
lineCap: LineCap
|
||||||
lineJoin: LineJoin
|
lineJoin: LineJoin
|
||||||
font: Font
|
font: Font
|
||||||
|
@ -41,6 +43,7 @@ proc newContext*(image: Image): Context =
|
||||||
result.image = image
|
result.image = image
|
||||||
result.mat = mat3()
|
result.mat = mat3()
|
||||||
result.lineWidth = 1
|
result.lineWidth = 1
|
||||||
|
result.miterLimit = 10
|
||||||
result.fillStyle = Paint(kind: pkSolid, color: rgbx(0, 0, 0, 255))
|
result.fillStyle = Paint(kind: pkSolid, color: rgbx(0, 0, 0, 255))
|
||||||
result.strokeStyle = Paint(kind: pkSolid, color: rgbx(0, 0, 0, 255))
|
result.strokeStyle = Paint(kind: pkSolid, color: rgbx(0, 0, 0, 255))
|
||||||
|
|
||||||
|
@ -52,6 +55,7 @@ proc state(ctx: Context): ContextState =
|
||||||
result.fillStyle = ctx.fillStyle
|
result.fillStyle = ctx.fillStyle
|
||||||
result.strokeStyle = ctx.strokeStyle
|
result.strokeStyle = ctx.strokeStyle
|
||||||
result.lineWidth = ctx.lineWidth
|
result.lineWidth = ctx.lineWidth
|
||||||
|
result.miterLimit = ctx.miterLimit
|
||||||
result.lineCap = ctx.lineCap
|
result.lineCap = ctx.lineCap
|
||||||
result.lineJoin = ctx.lineJoin
|
result.lineJoin = ctx.lineJoin
|
||||||
result.font = ctx.font
|
result.font = ctx.font
|
||||||
|
@ -85,6 +89,7 @@ proc restore*(ctx: Context) =
|
||||||
ctx.fillStyle = state.fillStyle
|
ctx.fillStyle = state.fillStyle
|
||||||
ctx.strokeStyle = state.strokeStyle
|
ctx.strokeStyle = state.strokeStyle
|
||||||
ctx.lineWidth = state.lineWidth
|
ctx.lineWidth = state.lineWidth
|
||||||
|
ctx.miterLimit = state.miterLimit
|
||||||
ctx.lineCap = state.lineCap
|
ctx.lineCap = state.lineCap
|
||||||
ctx.lineJoin = state.lineJoin
|
ctx.lineJoin = state.lineJoin
|
||||||
ctx.font = state.font
|
ctx.font = state.font
|
||||||
|
@ -118,7 +123,8 @@ proc stroke(ctx: Context, image: Image, path: Path) {.inline.} =
|
||||||
ctx.mat,
|
ctx.mat,
|
||||||
ctx.lineWidth,
|
ctx.lineWidth,
|
||||||
ctx.lineCap,
|
ctx.lineCap,
|
||||||
ctx.lineJoin
|
ctx.lineJoin,
|
||||||
|
ctx.miterLimit
|
||||||
)
|
)
|
||||||
|
|
||||||
proc fillText(ctx: Context, image: Image, text: string, at: Vec2) {.inline.} =
|
proc fillText(ctx: Context, image: Image, text: string, at: Vec2) {.inline.} =
|
||||||
|
@ -155,7 +161,8 @@ proc strokeText(ctx: Context, image: Image, text: string, at: Vec2) {.inline.} =
|
||||||
ctx.lineWidth,
|
ctx.lineWidth,
|
||||||
hAlign = ctx.textAlign,
|
hAlign = ctx.textAlign,
|
||||||
lineCap = ctx.lineCap,
|
lineCap = ctx.lineCap,
|
||||||
lineJoin = ctx.lineJoin
|
lineJoin = ctx.lineJoin,
|
||||||
|
miterLimit = ctx.miterLimit
|
||||||
)
|
)
|
||||||
|
|
||||||
proc beginPath*(ctx: Context) {.inline.} =
|
proc beginPath*(ctx: Context) {.inline.} =
|
||||||
|
|
|
@ -442,7 +442,8 @@ proc strokeText*(
|
||||||
transform: Vec2 | Mat3 = vec2(0, 0),
|
transform: Vec2 | Mat3 = vec2(0, 0),
|
||||||
strokeWidth = 1.0,
|
strokeWidth = 1.0,
|
||||||
lineCap = lcButt,
|
lineCap = lcButt,
|
||||||
lineJoin = ljMiter
|
lineJoin = ljMiter,
|
||||||
|
miterLimit = defaultMiterLimit
|
||||||
) =
|
) =
|
||||||
## Strokes the text arrangement.
|
## Strokes the text arrangement.
|
||||||
for spanIndex, (start, stop) in arrangement.spans:
|
for spanIndex, (start, stop) in arrangement.spans:
|
||||||
|
@ -470,7 +471,8 @@ proc strokeText*(
|
||||||
hAlign = haLeft,
|
hAlign = haLeft,
|
||||||
vAlign = vaTop,
|
vAlign = vaTop,
|
||||||
lineCap = lcButt,
|
lineCap = lcButt,
|
||||||
lineJoin = ljMiter
|
lineJoin = ljMiter,
|
||||||
|
miterLimit = defaultMiterLimit
|
||||||
) {.inline.} =
|
) {.inline.} =
|
||||||
## Typesets and strokes the text. Optional parameters:
|
## Typesets and strokes the text. Optional parameters:
|
||||||
## transform: translation or matrix to apply
|
## transform: translation or matrix to apply
|
||||||
|
|
|
@ -36,7 +36,9 @@ type
|
||||||
|
|
||||||
SomePath* = Path | string | seq[seq[Vec2]]
|
SomePath* = Path | string | seq[seq[Vec2]]
|
||||||
|
|
||||||
const epsilon = 0.0001 * PI ## Tiny value used for some computations.
|
const
|
||||||
|
epsilon = 0.0001 * PI ## Tiny value used for some computations.
|
||||||
|
defaultMiterLimit*: float32 = 4
|
||||||
|
|
||||||
when defined(release):
|
when defined(release):
|
||||||
{.push checks: off.}
|
{.push checks: off.}
|
||||||
|
@ -1546,7 +1548,7 @@ proc strokePath*(
|
||||||
strokeWidth = 1.0,
|
strokeWidth = 1.0,
|
||||||
lineCap = lcButt,
|
lineCap = lcButt,
|
||||||
lineJoin = ljMiter,
|
lineJoin = ljMiter,
|
||||||
miterLimit: float32 = 4,
|
miterLimit = defaultMiterLimit,
|
||||||
dashes: seq[float32] = @[],
|
dashes: seq[float32] = @[],
|
||||||
) =
|
) =
|
||||||
## Strokes a path.
|
## Strokes a path.
|
||||||
|
@ -1569,7 +1571,7 @@ proc strokePath*(
|
||||||
strokeWidth = 1.0,
|
strokeWidth = 1.0,
|
||||||
lineCap = lcButt,
|
lineCap = lcButt,
|
||||||
lineJoin = ljMiter,
|
lineJoin = ljMiter,
|
||||||
miterLimit: float32 = 4,
|
miterLimit = defaultMiterLimit,
|
||||||
dashes: seq[float32] = @[]
|
dashes: seq[float32] = @[]
|
||||||
) =
|
) =
|
||||||
## Strokes a path.
|
## Strokes a path.
|
||||||
|
|
Loading…
Reference in a new issue