#!/usr/bin/env ruby
# Generate motherboard form-factors comparison picture in SVG
# (C) Mikhail Yakshin AKA GreyCat, 2007
# License: GPL
WIDTH=4500
HEIGHT=3750
START_X=50
START_Y=50
MARK_LENGTH=30
ARROW_SIZE=100
MARK_STEP=500
# Sizes to show in comparison picture (in mm)
# w - width
# h - height
# ty - if present, text will be shifted by that amount on y coordinate
RECTS = [
{ :name => 'WTX', :w => 425, :h => 356 },
{ :name => 'SSI EEB 3.5' :w => 305, :h => 330 },
{ :name => 'BTX', :w => 325, :h => 267 },
{ :name => 'SSI CEB' :w => 305, :h => 267 },
{ :name => 'MicroBTX', :w => 264, :h => 267 },
{ :name => 'NanoBTX', :w => 224, :h => 267, :ty => 9 },
{ :name => 'PicoBTX', :w => 203, :h => 267 },
{ :name => 'ATX', :w => 305, :h => 244 },
{ :name => 'AT', :w => 305, :h => 305 },
{ :name => 'E-ATX', :w => 305, :h => 330 },
{ :name => 'MicroATX', :w => 244, :h => 244 },
{ :name => 'DTX', :w => 200, :h => 244 },
{ :name => 'FlexATX', :w => 229, :h => 191 },
{ :name => 'MiniDTX', :w => 200, :h => 170 },
{ :name => 'EBX', :w => 203, :h => 147 },
{ :name => 'MiniITX', :w => 170, :h => 170 },
{ :name => 'MiniATX', :w => 284, :h => 208 },
{ :name => 'NanoITX', :w => 120, :h => 120 },
{ :name => 'EPIC', :w => 165, :h => 115 },
{ :name => 'ETX/XTX', :w => 95, :h => 114 },
{ :name => 'PC/104', :w => 95, :h => 90 },
{ :name => 'PicoITX', :w => 72, :h => 100 },
{ :name => 'mnIII', :w => 225, :h => 170 },
{ :name => 'DIN A3', :w => 420, :h => 297, :paper => true },
{ :name => 'DIN A4', :w => 297, :h => 210, :paper => true },
{ :name => 'DIN A5', :w => 210, :h => 148, :paper => true, :ty => 9 },
]
# Header
puts <<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="#{WIDTH}"
height="#{HEIGHT}"
id="svg2"
version="1.0">
<defs
id="defs4" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<linearGradient id="mb_gradient" gradientUnits="objectBoundingBox" x1="0" y1="0" x2="1" y2="1">
<stop style="stop-color:white;" offset="0.8"/>
<stop style="stop-color:#78a3d1;" offset="1"/>
</linearGradient>
EOF
# Rectangles
RECTS.each { |b|
board_id = b[:name].downcase.gsub(/\//, '-')
ty = b[:h] + START_Y - 1
ty += b[:ty] if b[:ty]
if b[:paper]
puts " <rect style=\"opacity:1;fill:none;stroke:#b50e70;stroke-width:0.6;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:7.2,7.2;stroke-opacity:1;stroke-dashoffset:0\""
else
puts " <rect style=\"opacity:1;fill:url(#mb_gradient);fill-opacity:0.5;stroke:black;stroke-width:0.5;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1\""
end
puts <<EOF
id="#{board_id}"
width="#{b[:w]}"
height="#{b[:h]}"
x="#{START_X}"
y="#{START_Y}" />
<text
xml:space="preserve"
style="font-size:6px;text-align:end;text-anchor:end;font-family:sans-serif"
x="#{b[:w] + START_X - 1}"
y="#{ty}"
id="#{board_id}_text">#{b[:name]}</text>
EOF
}
# Axis
puts <<EOF
<path
style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:black;stroke-width:1.4px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 0,#{START_Y} L #{WIDTH},#{START_Y}"
id="x-axis" />
<path
style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:black;stroke-width:1.4px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M #{START_X},0 L #{START_X},#{HEIGHT}"
id="y-axis" />
EOF
# X-axis marks
1.upto(((WIDTH - START_X) / MARK_STEP).to_i) { |i|
value = i * MARK_STEP
puts <<EOF
<path
style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:black;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M #{START_X + value},#{START_Y - MARK_LENGTH} L #{START_X + value},#{START_Y + MARK_LENGTH}"
id="x-mark#{i}" />
<text
style="font-size:8px;font-family:sans-serif;text-anchor:middle"
x="#{START_X + value}"
y="#{START_Y + 2.5 + 8}"
id="x-mark#{i}-text">#{value}</text>
EOF
}
# Y-axis marks
1.upto(((HEIGHT - START_Y) / MARK_STEP).to_i) { |i|
value = i * 50
puts <<EOF
<path
style="fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:black;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M #{START_X - MARK_LENGTH},#{START_Y + value}, L #{START_X + MARK_LENGTH},#{START_Y + value}"
id="y-mark#{i}" />
<text
style="font-size:8px;font-family:sans-serif"
x="#{START_X + 2.5}"
y="#{START_Y + value + 2.5}"
id="y-mark#{i}-text">#{value}</text>
EOF
}
# Arrows
puts <<EOF
<path
style="fill:black;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M #{WIDTH},#{START_Y} L #{WIDTH - ARROW_SIZE},#{START_Y - MARK_LENGTH} L #{WIDTH - ARROW_SIZE},#{START_Y + MARK_LENGTH} z "
id="x-arrow" />
<path
style="fill:black;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M #{START_X},#{HEIGHT}, L #{START_X - MARK_LENGTH},#{HEIGHT - ARROW_SIZE} L #{START_X + MARK_LENGTH},#{HEIGHT - ARROW_SIZE} z "
id="y-arrow" />
</svg>
EOF