usps_flags 0.1.22 → 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dace6158b2076b70f5fb033140ea4b21cee7f967
4
- data.tar.gz: a84a6f03e81f6bdd576767af0aeedcc8169e182c
3
+ metadata.gz: 4eb2bb465ea98027be783774361565835284da8c
4
+ data.tar.gz: d0a3264c452cb0e0c5d04776e90842369018584d
5
5
  SHA512:
6
- metadata.gz: 420a31fe39f59bb6555a58d1cb0647f3bf3d19459efbcf1a06537ed91c1314a4fbcc6b68e42b9b0c25b7c776c7f34c07a1e6995b06deae676a078e67a1628c4a
7
- data.tar.gz: f1f9f5d2703aa67b45a7724fc78b97407b0f9e268dcb0b6b69739975e5679499d8b74089b40ab7d5f575f4f9c7344ef2694550eb612cdab4d008575fee7b14ef
6
+ metadata.gz: a3ed6492c6a9085c49fc6e0c85fab9e29fbfb3fed05181d81a9838e99e19521a40bbc55d8061f4688421c2312897061f18173c247b779ead2416353d6c4dcd54
7
+ data.tar.gz: d065f73fb7f67caf7d751444ec9e8e13918ee13ed195560869a5aab5a7bf9731a13ee7c0d7fd66454e1d2c1dff29e8b7c68effdfb36551847ba003a97f10de81
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps_flags (0.1.21)
4
+ usps_flags (0.1.23)
5
5
  file_utils (~> 1.1, >= 1.1.2)
6
6
  mini_magick (~> 4.8, >= 4.8.0)
7
7
  rubyzip (~> 1.2, >= 1.2.1)
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # United States Power Squadrons® Flag Generator
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/usps_flags.svg)](https://badge.fury.io/rb/usps_flags)
3
+ [![Gem Version](https://img.shields.io/gem/v/usps_flags.svg)](https://rubygems.org/gems/usps_flags)
4
4
  [![Build Status](https://travis-ci.org/jfiander/usps-flags.svg)](https://travis-ci.org/jfiander/usps-flags)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/jfiander/usps-flags/badge.svg?branch=master)](https://coveralls.io/github/jfiander/usps-flags?branch=master)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/760b824f0edac3316a11/maintainability)](https://codeclimate.com/github/jfiander/usps-flags/maintainability)
6
7
 
7
8
  This gem allows you to generate precise SVG and PNG flag images based on official specifications.
8
9
 
@@ -0,0 +1,64 @@
1
+ # Core SVG data for the anchor insignia.
2
+ #
3
+ # This class should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Anchor
6
+ def initialize(color: :red)
7
+ @color_code = case color
8
+ when :red
9
+ "#BF0D3E"
10
+ when :white
11
+ "#FFFFFF"
12
+ end
13
+ end
14
+
15
+ def svg
16
+ <<~SVG
17
+ <mask id="anchor-mask">
18
+ <g>
19
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
20
+ <path fill="#000000" d="M1252.3076435897437 462.05128846153843
21
+ c-55.62957153846173-45.08196512820513-96.39672312820517 23.744812948717993-88.20503230769259 51.79489025641044 6.653223282051158 27.53726679487147 50.02959307692299 72.62890461538461 98.46155051282062 25.641023846153644-27.978308974358924-21.85968564102552-43.491535897435824-37.83963128205124-8.717984871794897-76.4102912820511
22
+ M1270.7816162109375 632.2105102539062
23
+ c11.54851016276666-6.899249317733052 39.425036990907756-18.726567019718118 51.28209197215574-38.46155724158655 18.5237216479145 6.418855931977646 41.891453418341825 56.769453150028085 42.05127579126565 78.97439966446314-44.455562242460246.1536644631529498-70.91589675334876-3.7750424355801897-92.82043457031227-4.102564102564088-.3660762785023053-20.3275216669839.4958814355788945-14.34922979993803-.5129331931091201-35.3846435546875
24
+ M1271.807373046875 800.9284542768429
25
+ c17.452943326530885-.46905043663332435 38.66574607901384-1.5444581957890477 72.82039701021631-2.051257011217899 19.28285605940755 11.288072979443086-54.75933644042357 64.92938750941744-76.92296424278834 66.15380859375-2.1636278023652267-19.80121994130843.7052539023432018-33.79374165575666-.00010016025635195547-64.61535801031664
26
+ M1189.4276123046875 1008.6016845703125
27
+ c2.974817410010928 29.162871686922244.9565995146047044 90.80892096853563-5.128155048076906 121.53843336838918-40.443728921655975-2.6038209334792555-89.68029403366631-82.60878014049194 3.0768291766826223-122.05126170622987
28
+ M1322.38818359375 1290.0933837890625
29
+ c19.593626045193105-1.2347605841421228 95.16059107098704 40.021664246269665 96.4102783203125 68.718017578125-14.134928135289783 16.901481536983738-35.666444420437074 27.636734330172885-47.17954351963135 29.743511493389406-22.282329868425222-9.688094631655076-55.15658121378351-81.19370160837752-50.256350786258054-97.4358097956731" />
30
+ </g>
31
+ </mask>
32
+
33
+ <path mask="url(#anchor-mask)" fill="#{@color_code}" d="M1182.0512562460422,634.8718105128619
34
+ c-127.50414031806645,-57.87980084448043,-98.33494194360924,-157.05652261543366,-81.0255763281848,-194.8718025641362
35
+ c38.84781387183102,-83.96914338466655,157.00304879489136,-82.85448702564872,195.89744384618598,-47.17948923074607
36
+ c24.53542477435849,21.316034000046102,60.18456838981683,51.05085879482306,57.435807435916786,113.84615205126914
37
+ c73.14866787698952,76.12863520509234,71.40198169752557,88.51520500000265,97.43599743583059,173.33334102563083
38
+ c98.8545389450071,4.818131232624637,99.55414898847789,104.61193489364757,-8.205124358939429,109.74356999999225
39
+ c-25.708004789625875,64.61882453844396,-67.14435745637093,120.94832935895647,-172.3077023077326,169.2307871794976
40
+ c-2.5992382255190023,70.84656448715225,13.776934159119264,186.8525220513062,24.61535871798901,234.8717266666564
41
+ c65.19738749240719,10.070483589747028,154.51026231285846,61.984337666644706,189.74357649238618,111.79495410250729
42
+ c8.566643512772089,-9.676561051226827,56.736362820500744,-40.8957688974217,57.43582615383093,-78.97439564107322
43
+ c-40.32617769227136,-22.694017358868905,-46.757061615423254,-10.478899461467563,-109.74353110771835,-21.53839897424041
44
+ c42.65456538984108,-37.726172794888726,207.59033528726195,-161.09545651288613,250.25639615380942,-265.6410794871937
45
+ c59.076290040109825,88.27497837399585,71.65445633351851,324.2269786926548,-2.051314102583092,434.871755473455
46
+ c-10.116031236063236,-44.227132350911916,-43.09869935336155,-84.09163111133012,-55.38462128203264,-96.41016701191643
47
+ c-29.72181832173783,50.24559976029536,-81.95636499161674,115.57349732649573,-102.56403256410249,133.33330897435894
48
+ c28.623098711290822,72.11880743166671,-7.261530212306525,225.5893488434565,-68.71791375372572,185.6409501984151
49
+ c-49.148681325965754,-15.333037922763424,18.549622107753976,-115.55505291498798,-7.1795841949922306,-107.69228609585093
50
+ c-34.95998148195349,19.14481910912764,-167.90750204829328,129.20795509976756,-209.2307092307692,137.43596153846147
51
+ c-134.6565200483485,-54.336144923914844,-317.1862187488996,-216.49730227173723,-389.7436059656784,-330.25645686152825
52
+ c-38.71123409937445,37.01014857710106,-36.91255822003268,64.9171844290704,-48.205166417233386,92.30767560666914
53
+ c-55.39517986825638,-51.583890538004425,-94.67406936751138,-281.75614280779905,-29.74354259488905,-429.7435328612896
54
+ c18.77666857831457,47.91013041235192,164.53935578109724,200.61765517975073,269.7436206767652,257.4359318084928
55
+ c-64.02654995017485,6.5618535897069705,-112.85686466785285,11.954077594442651,-115.8975015964005,26.666604615348206
56
+ c13.369607980979595,27.020215106261958,110.16860728422273,133.64035296812426,184.61540871794875,151.7948817948718
57
+ c38.54936064125013,-35.17882824956223,61.75817892673331,-120.13381382049238,62.564074222199,-170.2563782051027
58
+ c-112.01461673846143,-68.58411333497293,-195.4475277093784,-202.73504102566642,21.538517829083048,-313.8462020513076
59
+ c-0.44986397943876,-39.31628256413069,3.6634418754476883,-100.03343099000347,-4.10254271451231,-111.79488372654134
60
+ c-172.89423135404945,-4.5819764834471925,-241.96276383285397,15.050453377662961,-246.15389305299936,-45.1281958802341
61
+ c-1.1141929951265865,-65.30684495420007,65.9235006844765,-60.74779963470837,241.02560210253228,-73.84616725825663" />
62
+ SVG
63
+ end
64
+ end
@@ -0,0 +1,22 @@
1
+ # Core SVG data for the binoculars insignia.
2
+ #
3
+ # This class should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Binoculars
6
+ def initialize(type: :d)
7
+ @color = case type
8
+ when :d
9
+ USPSFlags::Config::RED
10
+ when :n
11
+ USPSFlags::Config::BLUE
12
+ end
13
+ end
14
+
15
+ def svg
16
+ <<~SVG
17
+ <polyline fill="#{@color}" points="700 1500 760 600 825 600 825 540 760 540 760 480 1030 480 1030 540 965 540 965 600 1030 600 1090 1500" />
18
+ <polyline fill="#{@color}" transform="translate(660)" points="700 1500 760 600 825 600 825 540 760 540 760 480 1030 480 1030 540 965 540 965 600 1030 600 1090 1500" />
19
+ <polyline fill="#{@color}" points="1000 690 1150 690 1150 660 1300 660 1300 690 1450 690 1450 740 1275 740 1275 1380 1390 1380 1390 1430 1060 1430 1060 1380 1175 1380 1175 740 1000 740"/>
20
+ SVG
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+ # Core SVG data for the USPS Ensign.
2
+ #
3
+ # This class should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Ensign
6
+ def svg
7
+ field = <<~SVG
8
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#{USPSFlags::Config::BLUE}" />
9
+ <rect x="#{USPSFlags::Config::BASE_FLY*1/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#FFFFFF" />
10
+ <rect x="#{USPSFlags::Config::BASE_FLY*2/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#{USPSFlags::Config::BLUE}" />
11
+ <rect x="#{USPSFlags::Config::BASE_FLY*3/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#FFFFFF" />
12
+ <rect x="#{USPSFlags::Config::BASE_FLY*4/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#{USPSFlags::Config::BLUE}" />
13
+ <rect x="#{USPSFlags::Config::BASE_FLY*5/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#FFFFFF" />
14
+ <rect x="#{USPSFlags::Config::BASE_FLY*6/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#{USPSFlags::Config::BLUE}" />
15
+ <rect x="#{USPSFlags::Config::BASE_FLY*7/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#FFFFFF" />
16
+ <rect x="#{USPSFlags::Config::BASE_FLY*8/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#{USPSFlags::Config::BLUE}" />
17
+ <rect x="#{USPSFlags::Config::BASE_FLY*9/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#FFFFFF" />
18
+ <rect x="#{USPSFlags::Config::BASE_FLY*10/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#{USPSFlags::Config::BLUE}" />
19
+ <rect x="#{USPSFlags::Config::BASE_FLY*11/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#FFFFFF" />
20
+ <rect x="#{USPSFlags::Config::BASE_FLY*12/13}" y="0" width="#{USPSFlags::Config::BASE_FLY/13}" height="#{USPSFlags::Config::BASE_HOIST}" fill="#{USPSFlags::Config::BLUE}" />
21
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY*6/13}" height="1000" fill="#{USPSFlags::Config::RED}" />
22
+ SVG
23
+ # <circle cx="#{USPSFlags::Config::BASE_FLY*3/13}" cy="#{USPSFlags::Config::BASE_HOIST/4}" r="#{USPSFlags::Config::BASE_FLY*6/13*5/16}" fill="#FFFFFF" fill-opacity="0.6" />
24
+
25
+ anchor = USPSFlags::Core::Anchor.new(color: :white).svg
26
+
27
+ star_circle = ""
28
+ (0..13).each do |i|
29
+ rotation = i * (360.0 / 13)
30
+ star_circle << <<~SVG
31
+ <g transform="scale(0.375)">
32
+ <g transform="translate(1885, 465)">
33
+ <g transform="rotate(#{rotation}, 0, 900)">
34
+ #{USPSFlags::Core::Star.new.svg}
35
+ </g>
36
+ </g>
37
+ </g>
38
+ SVG
39
+ end
40
+
41
+ <<~SVG
42
+ #{field}
43
+ <g transform="scale(0.3675)">
44
+ <g transform="translate(1200, 600)">
45
+ <g transform="rotate(-45, 693, 1500)">
46
+ #{anchor}
47
+ </g>
48
+ </g>
49
+ </g>
50
+ #{star_circle}
51
+ SVG
52
+ end
53
+ end
@@ -0,0 +1,78 @@
1
+ # Core SVG data for the flag fields.
2
+ #
3
+ # This class should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Field
6
+ def initialize(style: :regular, color: :white, fly: USPSFlags::Config::BASE_FLY)
7
+ @style = style
8
+ @fly = fly
9
+ case color
10
+ when :white
11
+ border = true
12
+ @color_code = "#FFFFFF"
13
+ @past_mid_color = USPSFlags::Config::BLUE
14
+ @past_tail_color = USPSFlags::Config::RED
15
+ when :red
16
+ border = false
17
+ @color_code = USPSFlags::Config::RED
18
+ @past_mid_color = "#FFFFFF"
19
+ @past_tail_color = USPSFlags::Config::BLUE
20
+ when :blue
21
+ border = false
22
+ @color_code = USPSFlags::Config::BLUE
23
+ @past_mid_color = "#FFFFFF"
24
+ @past_tail_color = USPSFlags::Config::RED
25
+ end
26
+ @border_svg = border ? "stroke=\"#000000\" stroke-width=\"#{USPSFlags::Config::BASE_FLY/600}\" " : ""
27
+
28
+ @hoist = (@fly * 2) / 3
29
+ end
30
+
31
+ def svg
32
+ case @style
33
+ when :regular
34
+ <<~FIELD
35
+ <path d="M 0 0
36
+ l #{@fly} 0
37
+ l 0 #{@hoist}
38
+ l -#{@fly} 0
39
+ l 0 -#{@hoist}
40
+ " fill="#{@color_code}" #{@border_svg}/>
41
+ FIELD
42
+ when :swallowtail
43
+ <<~FIELD
44
+ <path d="M 0 0
45
+ l #{@fly} #{@hoist/6}
46
+ l -#{@fly/5} #{@hoist/3}
47
+ l #{@fly/5} #{@hoist/3}
48
+ l -#{@fly} #{@hoist/6}
49
+ " fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
50
+ FIELD
51
+ when :past
52
+ <<~FIELD
53
+ <path d="M 0 0
54
+ l #{@fly/2} #{@hoist*1/12}
55
+ l 0 #{@hoist*10/12}
56
+ l -#{@fly/2} #{@hoist*1/12}
57
+ " fill="#{@color_code}" />
58
+ <path d="M #{@fly/2} #{@hoist*1/12}
59
+ l #{@fly/4} #{@hoist*1/24}
60
+ l 0 #{@hoist*9/12}
61
+ l -#{@fly/4} #{@hoist*1/24}
62
+ " fill="#{@past_mid_color}" />
63
+ <path d="M #{@fly*3/4} #{@hoist*3/24}
64
+ l #{@fly/4} #{@hoist*1/24}
65
+ l -#{@fly/5} #{@hoist/3}
66
+ l #{@fly/5} #{@hoist/3}
67
+ l -#{@fly/4} #{@hoist*1/24}
68
+ " fill="#{@past_tail_color}" />
69
+ <path d="M 0 0
70
+ l #{@fly} #{@hoist/6}
71
+ l -#{@fly/5} #{@hoist/3}
72
+ l #{@fly/5} #{@hoist/3}
73
+ l -#{@fly} #{@hoist/6}
74
+ " fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
75
+ FIELD
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,11 @@
1
+ # Core SVG data for the file footer.
2
+ #
3
+ # This class should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Footer
6
+ def svg
7
+ <<~FOOTER
8
+ </svg>
9
+ FOOTER
10
+ end
11
+ end
@@ -0,0 +1,60 @@
1
+ # Core SVG data for the file headers.
2
+ #
3
+ # This class should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Headers
6
+ def initialize(width: nil, height: nil, pennant: false, scale: nil, title: "USPS Flag")
7
+ @width = width
8
+ @height = height
9
+ @title = title
10
+ if @width.nil? || @height.nil?
11
+ scale = 3 if scale.nil?
12
+ @width = USPSFlags::Config::BASE_FLY / scale
13
+ @height = (@width*Rational(2,3)).to_i
14
+
15
+ @view_width = USPSFlags::Config::BASE_FLY
16
+ @view_height = USPSFlags::Config::BASE_HOIST
17
+
18
+ if pennant
19
+ @height = @height/4
20
+ @view_height = USPSFlags::Config::BASE_HOIST/4
21
+ end
22
+ else
23
+ if scale.nil?
24
+ @view_width = @width
25
+ @view_height = @height
26
+ else
27
+ @view_width = @width * scale
28
+ @view_height = @height * scale
29
+ end
30
+ end
31
+
32
+ @generated_at = Time.now.strftime("%Y%m%d.%H%S%z")
33
+ end
34
+
35
+ def svg
36
+ svg = ""
37
+ svg << <<~SVG
38
+ <?xml version="1.0" standalone="no"?>
39
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
40
+ <svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="#{@width}pt" height="#{@height}pt" viewBox="0 0 #{@view_width} #{@view_height}" preserveAspectRatio="xMidYMid meet">
41
+ <title>#{@title}</title>
42
+ <metadata>
43
+ <desc id="created-by">Julian Fiander</desc>
44
+ <desc id="generated-at">#{@generated_at}</desc>
45
+ SVG
46
+
47
+ unless @title == "US Ensign"
48
+ svg << <<~SVG
49
+ <desc id="trademark-desc">This image is a registered trademark of United States Power Squadrons.</desc>
50
+ <desc id="trademark-link">http://www.usps.org/national/itcom/trademark.html</desc>
51
+ SVG
52
+ end
53
+
54
+ svg << <<~SVG
55
+ </metadata>
56
+ SVG
57
+
58
+ svg
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ # Core SVG data for the lighthouse insignia.
2
+ #
3
+ # This class should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Lighthouse
6
+ def svg
7
+ <<~SVG
8
+ <mask id="lighthouse-mask">
9
+ <g>
10
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
11
+ <rect x="1150" y="540" fill="#000000" width="80" height="140" />
12
+ <rect x="1270" y="540" fill="#000000" width="80" height="140" />
13
+ <polyline fill="#000000" points="1065 690 1065 725 1075 725 1095 710 1095 690" />
14
+ <polyline fill="#000000" points="1405 690 1435 690 1435 725 1425 725 1405 710" />
15
+ <polyline fill="#000000" points="1065 760 1065 790 1085 775 1085 760" />
16
+ <polyline fill="#000000" points="1435 760 1415 760 1415 775 1435 790" />
17
+ </g>
18
+ </mask>
19
+
20
+ <g mask="url(#lighthouse-mask)">
21
+ <polyline fill="#{USPSFlags::Config::RED}" points="1100 475 1100 450 1200 400 1200 350 1300 350 1300 400 1400 450 1400 475" />
22
+ <polyline fill="#{USPSFlags::Config::RED}" points="1050 800 1050 675 1100 675 1100 500 1400 500 1400 675 1450 675 1450 800" />
23
+ <polyline fill="#{USPSFlags::Config::RED}" points="1050 825 1075 875 1425 875 1450 825" />
24
+ <polyline fill="#{USPSFlags::Config::RED}" points="900 1500 1075 900 1425 900 1600 1500" />
25
+ <polyline fill="#{USPSFlags::Config::RED}" points="900 1525 925 1575 1575 1575 1600 1525" />
26
+ </g>
27
+ SVG
28
+ end
29
+ end
@@ -0,0 +1,46 @@
1
+ # Core SVG data for the pennants.
2
+ #
3
+ # This class should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Pennant
6
+ def initialize(type: :cruise)
7
+ @type = type.to_s.upcase
8
+ @fly = USPSFlags::Config::BASE_FLY
9
+ @hoist = USPSFlags::Config::BASE_HOIST/4
10
+ end
11
+
12
+ def svg
13
+ if @type == "OIC"
14
+ svg = <<~SVG
15
+ <polyline fill="#{USPSFlags::Config::BLUE}" points="0 0 #{USPSFlags::Config::BASE_FLY} #{USPSFlags::Config::BASE_HOIST/8} 0 #{USPSFlags::Config::BASE_HOIST/4}" />
16
+ SVG
17
+ elsif @type == "CRUISE"
18
+ svg = <<~FIELD
19
+ <path d="M 0 0
20
+ l #{fly*10/36} #{hoist*5/36}
21
+ l 0 #{hoist*26/36}
22
+ l -#{fly*10/36} #{hoist*5/36}
23
+ " fill="#{USPSFlags::Config::RED}" />
24
+ <path d="M #{fly*10/36} #{hoist*5/36}
25
+ l #{fly*11/36} #{hoist*5.5/36}
26
+ l 0 #{hoist*15/36}
27
+ l -#{fly*11/36} #{hoist*5.5/36}
28
+ " fill="#FFFFFF" />
29
+ <path d="M #{fly*21/36} #{hoist*10.5/36}
30
+ l #{fly*15/36} #{hoist*7.5/36}
31
+ l -#{fly*15/36} #{hoist*7.5/36}
32
+ " fill="#{USPSFlags::Config::BLUE}" />
33
+ <path d="M 0 0
34
+ l #{fly} #{hoist/2}
35
+ l -#{fly} #{hoist/2}
36
+ " fill="none" stroke="#000000" stroke-width="2" />
37
+ FIELD
38
+
39
+ svg << "<g transform=\"translate(385, 340)\">"
40
+ svg << USPSFlags::Core::Star.new.svg
41
+ svg << "</g>"
42
+
43
+ svg
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ # Core SVG data for stars.
2
+ #
3
+ # This class should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Star
6
+ def svg
7
+ points = [
8
+ [117.555, 81.805],
9
+ [-41.47, -137.085],
10
+ [114.125, -86.525],
11
+ [-143.185, -2.915],
12
+ [-47.025, -135.28],
13
+ [-47.025, 135.28],
14
+ [-143.185, 2.915],
15
+ [114.125, 86.525],
16
+ [-41.47, 137.085],
17
+ [117.555, -81.805]
18
+ ]
19
+
20
+ svg = "<path d=\"M 0 0\n"
21
+
22
+ points.each do |x, y|
23
+ svg << "l #{x} #{y}\n"
24
+ end
25
+
26
+ svg << "\" fill=\"#FFFFFF\" />\n"
27
+
28
+ svg
29
+ end
30
+ end
@@ -0,0 +1,166 @@
1
+ # Core SVG data for the trident insignia.
2
+ #
3
+ # This class should never need to be called directly.
4
+ # @private
5
+ class USPSFlags::Core::Trident
6
+ def initialize(type, color: :blue, field_color: nil)
7
+ valid_types = [:s, :d, :stf, :n]
8
+ raise "Error: Invalid trident type. Options are #{valid_types}." unless valid_types.include? type
9
+ @type = type
10
+
11
+ @trident_config = USPSFlags::Config.trident
12
+ main_spike_overhang = @trident_config[:bar_width] / 2
13
+ side_spike_overhang = @trident_config[:bar_width] / 2
14
+ @top_point = ((USPSFlags::Config::BASE_HOIST - @trident_config[:height][@type]) / 2)
15
+ crossbar_top = @top_point + @trident_config[:crossbar_from_top]
16
+ @hash_from_top = @trident_config[:crossbar_from_top] + (@trident_config[:bar_width] * 2)
17
+ @circle_from_top = @trident_config[:crossbar_from_top] + @trident_config[:bar_width]*123/128 + @trident_config[:width]/2
18
+ main_length = @trident_config[:height][@type] - (@trident_config[:point_height] - @trident_config[:main_point_barb])
19
+
20
+ @trident_segments = [
21
+ {
22
+ # Main spike
23
+ [@trident_config[:center_point], @top_point] =>
24
+ [
25
+ [@trident_config[:bar_width], @trident_config[:point_height]],
26
+ [-main_spike_overhang, -@trident_config[:main_point_barb]],
27
+ [0, main_length],
28
+ [-(@trident_config[:bar_width]), 0],
29
+ [0, -main_length],
30
+ [-main_spike_overhang, @trident_config[:main_point_barb]],
31
+ [@trident_config[:bar_width], -@trident_config[:point_height]]
32
+ ]
33
+ },
34
+ {
35
+ # Crossbar
36
+ [(@trident_config[:center_point] - @trident_config[:width]/2), (crossbar_top)] =>
37
+ [
38
+ [@trident_config[:width], 0],
39
+ [0, @trident_config[:bar_width]],
40
+ [-@trident_config[:width], 0],
41
+ [0, -@trident_config[:bar_width]]
42
+ ]
43
+ },
44
+ {
45
+ # Left spike
46
+ [(@trident_config[:center_point] - @trident_config[:width]/2), (crossbar_top + 1)] =>
47
+ [
48
+ [0, -(@trident_config[:side_spike_height]+@trident_config[:point_height])],
49
+ [(@trident_config[:bar_width]+side_spike_overhang), @trident_config[:point_height]],
50
+ [-side_spike_overhang, 0],
51
+ [0, @trident_config[:side_spike_height]]
52
+ ]
53
+ },
54
+ {
55
+ # Right spike
56
+ [(@trident_config[:center_point] + @trident_config[:width]/2), (crossbar_top + 1)] =>
57
+ [
58
+ [0, -(@trident_config[:side_spike_height]+@trident_config[:point_height])],
59
+ [-(@trident_config[:bar_width]+side_spike_overhang), @trident_config[:point_height]],
60
+ [side_spike_overhang, 0],
61
+ [0, @trident_config[:side_spike_height]]
62
+ ]
63
+ }
64
+ ]
65
+
66
+ @lower_hash = [
67
+ [@trident_config[:hash_width], 0],
68
+ [0, @trident_config[:bar_width]],
69
+ [-@trident_config[:hash_width], 0],
70
+ [0, -@trident_config[:bar_width]]
71
+ ]
72
+
73
+ case color
74
+ when :white
75
+ @color_code = "#FFFFFF"
76
+ @field_color_code = case field_color
77
+ when :red
78
+ USPSFlags::Config::RED
79
+ when :blue
80
+ USPSFlags::Config::BLUE
81
+ end
82
+ when :red
83
+ @color_code = USPSFlags::Config::RED
84
+ @field_color_code = "#FFFFFF"
85
+ when :blue
86
+ @color_code = USPSFlags::Config::BLUE
87
+ @field_color_code = "#FFFFFF"
88
+ end
89
+ end
90
+
91
+ def svg
92
+ svg = case @type
93
+ when :d
94
+ "<g mask=\"url(#delta-mask)\">"
95
+ when :stf
96
+ "<g mask=\"url(#circle-mask-for-main-spike)\">"
97
+ else
98
+ ""
99
+ end
100
+
101
+ @trident_segments.each do |segment|
102
+ start = segment.keys.first
103
+ points = segment.values.first
104
+ svg << "<path d=\"M #{start[0]} #{start[1]}\n"
105
+ points.each do |x, y|
106
+ svg << "l #{x} #{y}\n"
107
+ end
108
+ svg << "\" fill=\"#{@color_code}\" />\n"
109
+ end
110
+ svg << "</g>" if [:d, :stf].include?(@type)
111
+
112
+ if @type == :d
113
+ # Delta hash
114
+ svg << <<~SVG
115
+ <polyline mask="url(#delta-mask)" fill="#{@color_code}" points="
116
+ #{@trident_config[:center_point]}, #{@top_point + @trident_config[:height][:d] - @trident_config[:delta_from_bottom] - @trident_config[:delta_height]}
117
+ #{@trident_config[:center_point] + @trident_config[:width]/2}, #{@top_point + @trident_config[:height][:d] - @trident_config[:delta_from_bottom]}
118
+ #{@trident_config[:center_point] - @trident_config[:width]/2}, #{@top_point + @trident_config[:height][:d] - @trident_config[:delta_from_bottom]}
119
+ #{@trident_config[:center_point]}, #{@top_point + @trident_config[:height][:d] - @trident_config[:delta_from_bottom] - @trident_config[:delta_height]}" />
120
+ <mask id="delta-mask">
121
+ <g>
122
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
123
+ <polyline transform="scale(#{@trident_config[:delta_gap_scale]}) translate(#{@trident_config[:delta_gap_x]},#{@trident_config[:delta_gap_y]})" fill="#000000" points="
124
+ #{@trident_config[:center_point]}, #{@top_point + @trident_config[:height][:d] - @trident_config[:delta_from_bottom] - @trident_config[:delta_height]}
125
+ #{@trident_config[:center_point] + @trident_config[:width]/2}, #{@top_point + @trident_config[:height][:d] - @trident_config[:delta_from_bottom]}
126
+ #{@trident_config[:center_point] - @trident_config[:width]/2}, #{@top_point + @trident_config[:height][:d] - @trident_config[:delta_from_bottom]}
127
+ #{@trident_config[:center_point]}, #{@top_point + @trident_config[:height][:d] - @trident_config[:delta_from_bottom] - @trident_config[:delta_height]}" />
128
+ </g>
129
+ </mask>
130
+ SVG
131
+ elsif @type == :stf
132
+ # Circle hash
133
+ svg << <<~SVG
134
+ <circle cx="#{@trident_config[:center_point]}" cy="#{@top_point + @circle_from_top}" r="#{@trident_config[:width]/2}" fill="#{@color_code}" mask="url(#circle-mask)" />
135
+ <mask id="circle-mask">
136
+ <g>
137
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
138
+ <circle cx="#{@trident_config[:center_point]}" cy="#{@top_point + @circle_from_top}" r="#{@trident_config[:width]/2-@trident_config[:bar_width]}" fill="#000000" />
139
+ </g>
140
+ </mask>
141
+ <mask id="circle-mask-for-main-spike">
142
+ <g transform="scale(1.05) translate(-@trident_config[:br_width], -@trident_config[:br_width]/2)">
143
+ <rect x="0" y="0" width="#{USPSFlags::Config::BASE_FLY}" height="#{USPSFlags::Config::BASE_FLY}" fill="#FFFFFF" />
144
+ <circle cx="#{@trident_config[:center_point]}" cy="#{@top_point + @circle_from_top}" r="#{@trident_config[:width]/2-@trident_config[:bar_width]}" fill="#000000" />
145
+ </g>
146
+ </mask>
147
+ SVG
148
+ else
149
+ # Standard hash
150
+ svg << "<path d=\"M #{(@trident_config[:center_point] - @trident_config[:hash_width]/2)} #{(@top_point + @hash_from_top)}\n"
151
+ @lower_hash.each do |x, y|
152
+ svg << "l #{x} #{y}\n"
153
+ end
154
+ svg << "\" fill=\"#{@color_code}\" />\n"
155
+
156
+ # # V/C crossing, marks @ 15/32 up
157
+ # vc_cross_marker = USPSFlags::Config::BASE_HOIST*7/8-(USPSFlags::Config::BASE_HOIST/8+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]*3)*15/32
158
+ # svg << "<line x1=\"#{USPSFlags::Config::BASE_FLY*3/8}\" x2=\"#{USPSFlags::Config::BASE_FLY*5/8}\" y1=\"#{vc_cross_marker}\" y2=\"#{vc_cross_marker}\" stroke=\"black\" stroke-width=\"#{USPSFlags::Config::BASE_FLY/600}\" />"
159
+ # # C/C crossing, marks @ 1/3 up
160
+ # cc_cross_marker = USPSFlags::Config::BASE_HOIST*7/8-(USPSFlags::Config::BASE_HOIST/8+@trident_config[:crossbar_from_top]+@trident_config[:bar_width]*3)*1/3
161
+ # svg << "<line x1=\"#{USPSFlags::Config::BASE_FLY*3/8}\" x2=\"#{USPSFlags::Config::BASE_FLY*5/8}\" y1=\"#{cc_cross_marker}\" y2=\"#{cc_cross_marker}\" stroke=\"black\" stroke-width=\"#{USPSFlags::Config::BASE_FLY/600}\" />"
162
+ end
163
+
164
+ svg
165
+ end
166
+ end