more icon sets, couple fixes
This commit is contained in:
parent
e41b8434eb
commit
dcf0a3fd60
5 changed files with 72 additions and 28 deletions
|
@ -143,6 +143,9 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
||||||
ty = parseFloat(components[1])
|
ty = parseFloat(components[1])
|
||||||
result.transform = result.transform * translate(vec2(tx, ty))
|
result.transform = result.transform * translate(vec2(tx, ty))
|
||||||
elif f.startsWith("rotate("):
|
elif f.startsWith("rotate("):
|
||||||
|
# let
|
||||||
|
# values = f[7 .. ^2].split(" ")
|
||||||
|
# angle = parseFloat(values[0]) * -PI / 180
|
||||||
let angle = parseFloat(f[7 .. ^2]) * -PI / 180
|
let angle = parseFloat(f[7 .. ^2]) * -PI / 180
|
||||||
result.transform = result.transform * rotationMat3(angle)
|
result.transform = result.transform * rotationMat3(angle)
|
||||||
else:
|
else:
|
||||||
|
@ -198,11 +201,18 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) =
|
||||||
points = node.attr("points")
|
points = node.attr("points")
|
||||||
|
|
||||||
var vecs: seq[Vec2]
|
var vecs: seq[Vec2]
|
||||||
for pair in points.split(" "):
|
if points.contains(","):
|
||||||
let parts = pair.split(",")
|
for pair in points.split(" "):
|
||||||
if parts.len != 2:
|
let parts = pair.split(",")
|
||||||
|
if parts.len != 2:
|
||||||
|
failInvalid()
|
||||||
|
vecs.add(vec2(parseFloat(parts[0]), parseFloat(parts[1])))
|
||||||
|
else:
|
||||||
|
let points = points.split(" ")
|
||||||
|
if points.len mod 2 != 0:
|
||||||
failInvalid()
|
failInvalid()
|
||||||
vecs.add(vec2(parseFloat(parts[0]), parseFloat(parts[1])))
|
for i in countup(0, points.len - 2, 2):
|
||||||
|
vecs.add(vec2(parseFloat(points[i]), parseFloat(points[i + 1])))
|
||||||
|
|
||||||
if vecs.len == 0:
|
if vecs.len == 0:
|
||||||
failInvalid()
|
failInvalid()
|
||||||
|
@ -295,8 +305,8 @@ proc decodeSvg*(data: string, width = 0, height = 0): Image =
|
||||||
viewBox = root.attr("viewBox")
|
viewBox = root.attr("viewBox")
|
||||||
box = viewBox.split(" ")
|
box = viewBox.split(" ")
|
||||||
|
|
||||||
if parseInt(box[0]) != 0 or parseInt(box[1]) != 0:
|
# if parseInt(box[0]) != 0 or parseInt(box[1]) != 0:
|
||||||
failInvalid()
|
# failInvalid()
|
||||||
|
|
||||||
let
|
let
|
||||||
viewBoxWidth = parseInt(box[2])
|
viewBoxWidth = parseInt(box[2])
|
||||||
|
@ -319,5 +329,5 @@ proc decodeSvg*(data: string, width = 0, height = 0): Image =
|
||||||
result.toStraightAlpha()
|
result.toStraightAlpha()
|
||||||
except PixieError as e:
|
except PixieError as e:
|
||||||
raise e
|
raise e
|
||||||
except:
|
# except:
|
||||||
raise newException(PixieError, "Unable to load SVG")
|
# raise newException(PixieError, "Unable to load SVG")
|
||||||
|
|
BIN
tests/images/svg/flat-color-icons.png
Normal file
BIN
tests/images/svg/flat-color-icons.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 281 KiB |
BIN
tests/images/svg/ionicons.png
Normal file
BIN
tests/images/svg/ionicons.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 522 KiB |
Binary file not shown.
Before Width: | Height: | Size: 519 KiB After Width: | Height: | Size: 520 KiB |
|
@ -1,34 +1,68 @@
|
||||||
import os, pixie, pixie/fileformats/svg, strformat
|
import cligen, os, pixie, pixie/fileformats/svg, strformat
|
||||||
|
|
||||||
# Clone https://github.com/twbs/icons
|
# Clone https://github.com/twbs/icons
|
||||||
# Check out commit f364cb14dfc0703b9e3ef10c8b490a71dfef1e9d
|
# Check out commit f364cb14dfc0703b9e3ef10c8b490a71dfef1e9d
|
||||||
|
|
||||||
|
# Clone https://github.com/icons8/flat-color-icons
|
||||||
|
# Check out commit 8eccbbbd8b2af1d2c9593e7cfba5ecb0d68ee378
|
||||||
|
|
||||||
|
# Clone https://github.com/ionic-team/ionicons
|
||||||
|
# Check out commit 0d7f507677f8d317ce6882729ffecf46e215e01a
|
||||||
|
|
||||||
|
# Clone https://github.com/tabler/tabler-icons
|
||||||
|
# Check out commit ccf2784b57e42a2b2221963f92146fd7b249b5b7
|
||||||
|
|
||||||
|
# Clone https://github.com/simple-icons/simple-icons
|
||||||
|
# Check out commit 355454cb6caa02aba70638631c557d4e06205710
|
||||||
|
|
||||||
|
type IconSet = object
|
||||||
|
name: string
|
||||||
|
path: string
|
||||||
|
|
||||||
const
|
const
|
||||||
iconsPath = "../icons/icons/*"
|
iconSets = [
|
||||||
|
IconSet(name: "twbs-icons", path: "../icons/icons/*"),
|
||||||
|
IconSet(name: "flat-color-icons", path: "../flat-color-icons/svg/*"),
|
||||||
|
IconSet(name: "ionicons", path: "../ionicons/src/svg/*"),
|
||||||
|
# IconSet(name: "tabler-icons", path: "../tabler-icons/icons/*"),
|
||||||
|
# IconSet(name: "simple-icons", path: "../simple-icons/icons/*")
|
||||||
|
]
|
||||||
width = 32
|
width = 32
|
||||||
height = 32
|
height = 32
|
||||||
|
|
||||||
var images: seq[(string, Image)]
|
proc renderIconSet(index: int) =
|
||||||
|
let iconSet = iconSets[index]
|
||||||
|
|
||||||
|
var images: seq[(string, Image)]
|
||||||
|
|
||||||
|
for filePath in walkFiles(iconSet.path):
|
||||||
|
let
|
||||||
|
(_, name, _) = splitFile(filePath)
|
||||||
|
image = decodeSvg(readFile(filePath), width, height)
|
||||||
|
|
||||||
|
images.add((name, image))
|
||||||
|
|
||||||
for path in walkFiles(iconsPath):
|
|
||||||
let
|
let
|
||||||
(_, name, _) = splitFile(path)
|
columns = 50
|
||||||
image = decodeSvg(readFile(path), width, height)
|
rows = (images.len + columns - 1) div columns
|
||||||
|
rendered = newImage((width + 4) * columns, (height + 4) * rows)
|
||||||
|
|
||||||
images.add((name, image))
|
for i in 0 ..< rows:
|
||||||
|
for j in 0 ..< max(images.len - i * columns, 0):
|
||||||
|
let (_, icon) = images[i * columns + j]
|
||||||
|
rendered.draw(
|
||||||
|
icon,
|
||||||
|
vec2(((width + 4) * j + 2).float32, ((height + 4) * i + 2).float32),
|
||||||
|
bmOverwrite
|
||||||
|
)
|
||||||
|
|
||||||
let
|
rendered.writeFile(&"tests/images/svg/{iconSet.name}.png")
|
||||||
columns = 50
|
|
||||||
rows = (images.len + columns - 1) div columns
|
|
||||||
rendered = newImage((width + 4) * columns, (height + 4) * rows)
|
|
||||||
|
|
||||||
for i in 0 ..< rows:
|
proc main(index = -1) =
|
||||||
for j in 0 ..< max(images.len - i * columns, 0):
|
if index >= 0:
|
||||||
let (_, icon) = images[i * columns + j]
|
renderIconSet(index)
|
||||||
rendered.draw(
|
else:
|
||||||
icon,
|
for i in 0 ..< iconSets.len:
|
||||||
vec2(((width + 4) * j + 2).float32, ((height + 4) * i + 2).float32),
|
renderIconSet(i)
|
||||||
bmOverwrite
|
|
||||||
)
|
|
||||||
|
|
||||||
rendered.writeFile(&"tests/images/svg/twbs-icons.png")
|
dispatch(main)
|
||||||
|
|
Loading…
Reference in a new issue