|
@@ -2,7 +2,8 @@
|
|
|
import streams
|
|
|
import xmltree
|
|
|
import strutils
|
|
|
-from base64 import encode
|
|
|
+import strtabs
|
|
|
+import base64
|
|
|
|
|
|
|
|
|
type
|
|
@@ -14,11 +15,13 @@ type
|
|
|
value_text_color: string ## right text color
|
|
|
label_color: string ## left color.
|
|
|
value_color: string ## right color.
|
|
|
- font: string
|
|
|
+ font: string ## label and value font.
|
|
|
font_size: int
|
|
|
width, height: int
|
|
|
- image_path: string
|
|
|
- image_color: string
|
|
|
+ image_path: string ## image path for icon.
|
|
|
+ image_color: string ## image fill color.
|
|
|
+ label_shadow, value_shadow: bool
|
|
|
+ dx, dy: int
|
|
|
|
|
|
|
|
|
proc newBadge*(label="", value="", style="flat", label_color="#212121",
|
|
@@ -30,25 +33,35 @@ proc newBadge*(label="", value="", style="flat", label_color="#212121",
|
|
|
label_color: label_color, value_color: value_color,
|
|
|
font: "DejaVu Sans,Verdana,Geneva,sans-serif",
|
|
|
width: width, height: height, image_path: "", image_color: "",
|
|
|
- font_size: 12)
|
|
|
+ font_size: 12, label_shadow: false, value_shadow: false, dx: 0, dy: 0)
|
|
|
|
|
|
-proc setFont*(badge: BadgeRef, font: string) =
|
|
|
+proc setFont*(badge: BadgeRef, font: string) {.inline.} =
|
|
|
## Sets badge font.
|
|
|
badge.font = font
|
|
|
|
|
|
-proc setFontSize*(badge: BadgeRef, size: int) =
|
|
|
+proc setFontSize*(badge: BadgeRef, size: int) {.inline.} =
|
|
|
## Sets badge font size.
|
|
|
badge.font_size = size
|
|
|
|
|
|
-proc setIcon*(badge: BadgeRef, image_path: string) =
|
|
|
+proc setIcon*(badge: BadgeRef, image_path: string) {.inline.} =
|
|
|
## Sets icon for badge.
|
|
|
badge.image_path = image_path
|
|
|
|
|
|
-proc setIcon*(badge: BadgeRef, image_path, color: string) =
|
|
|
+proc setIcon*(badge: BadgeRef, image_path, color: string) {.inline.} =
|
|
|
## Sets icon with fill color.
|
|
|
badge.image_path = image_path
|
|
|
badge.image_color = color
|
|
|
|
|
|
+proc setShadow*(badge: BadgeRef, label=false, value=false) {.inline.} =
|
|
|
+ ## Change text drop shadow.
|
|
|
+ badge.label_shadow = label
|
|
|
+ badge.value_shadow = value
|
|
|
+
|
|
|
+proc offsetShadow*(badge: BadgeRef, dx, dy: int) {.inline.} =
|
|
|
+ ## Change drop shadow offset.
|
|
|
+ badge.dx = dx
|
|
|
+ badge.dy = dy
|
|
|
+
|
|
|
proc `$`*(badge: BadgeRef): string =
|
|
|
let
|
|
|
# start variables
|
|
@@ -67,6 +80,25 @@ proc `$`*(badge: BadgeRef): string =
|
|
|
labelw - badge.font_size + radius.parseInt
|
|
|
stop_opacity = if "plastic" notin badge.style: "0" else: ".1"
|
|
|
|
|
|
+ # Drop shadow effect.
|
|
|
+ var shadow = newXMLTree("defs", [], newStringTable(modeCaseSensitive))
|
|
|
+ shadow.add newXMLTree(
|
|
|
+ "filter", [], {
|
|
|
+ "id": "drop_shadow", "x": "0", "y": "0", "width": "200%", "height": "200%"
|
|
|
+ }.toXMLAttributes)
|
|
|
+ shadow[0].add newXMLTree(
|
|
|
+ "feOffset", [], {
|
|
|
+ "result": "offOut", "in": "SourceAlpha", "dx": $badge.dx, "dy": $badge.dy
|
|
|
+ }.toXMLAttributes)
|
|
|
+ shadow[0].add newXMLTree(
|
|
|
+ "feGaussianBlur", [], {
|
|
|
+ "result": "blurOut", "in": "offOut", "stdDeviation": "1"
|
|
|
+ }.toXMLAttributes)
|
|
|
+ shadow[0].add newXMLTree(
|
|
|
+ "feBlend", [], {
|
|
|
+ "in": "SourceGraphic", "in2": "blurOut", "mode": "normal"
|
|
|
+ }.toXMLAttributes)
|
|
|
+
|
|
|
var
|
|
|
# trees
|
|
|
tree = newXMLTree(
|
|
@@ -119,18 +151,21 @@ proc `$`*(badge: BadgeRef): string =
|
|
|
text.add newXMLTree(
|
|
|
"text", [], {
|
|
|
"x": $(image_width + 2 + parseInt(radius)),
|
|
|
- "y": $(badge.height/2 + (badge.font_size/2) - 1.0), "fill": badge.label_text_color
|
|
|
+ "y": $(badge.height/2 + (badge.font_size/2) - 1.0), "fill": badge.label_text_color,
|
|
|
+ "filter": if badge.label_shadow: "url(#drop_shadow)" else: ""
|
|
|
}.toXMLAttributes)
|
|
|
text.add newXMLTree(
|
|
|
"text", [], {
|
|
|
"x": $(dif + 2),
|
|
|
- "y": $(badge.height/2 + (badge.font_size/2) - 1.0), "fill": badge.value_text_color
|
|
|
+ "y": $(badge.height/2 + (badge.font_size/2) - 1.0), "fill": badge.value_text_color,
|
|
|
+ "filter": if badge.value_shadow: "url(#drop_shadow)" else: ""
|
|
|
}.toXMLAttributes)
|
|
|
|
|
|
text[0].add newText badge.label
|
|
|
text[1].add newText badge.value
|
|
|
|
|
|
tree.add gradient
|
|
|
+ tree.add shadow
|
|
|
tree.add main
|
|
|
tree.add text
|
|
|
if badge.image_path != "":
|