Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
_site/
.sass-cache/

# charmap files
*.charmap
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ collections:
output: true

exclude: [ "vendor/bundle" ]
#include: [ "_includes/charmaps" ]

29 changes: 29 additions & 0 deletions _includes/charmap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% assign charmap_name = page.styles.first[0] %}
{% for style in page.styles %}
{% if style[0] == '400' %}
{% capture charmap_name %}{{ style[0] }}{% endcapture %}
{% endif %}
{% endfor %}
{% capture charmap_path %}charmaps/{{ page.family }}/{{ charmap_name }}.html{% endcapture %}
{% capture charmap_path %}{{ charmap_path | replace: " " "" }}{% endcapture %}

{% capture charmap_id %}{{ page.family }}-{{ charmap_name }}{% endcapture %}
{% capture charmap_id %}{{ charmap_id | replace: " " "" }}{% endcapture %}
{% capture charmap_id %}/assets/charmap_template/{{ charmap_id }}{% endcapture %}

{% assign display = false %}
{% for static_file in site.static_files %}
{% if static_file.path == charmap_id %}
{% assign display = true %}
{% endif %}
{% endfor %}

{% unless display == false %}

<article class="charmap">
<span class="section">Character Map</span>
{% include {{charmap_path}} %}
</article>

{% endunless %}

1 change: 1 addition & 0 deletions _layouts/font.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ <h6 data-desc="h6" contenteditable>Kiwi jam overfilled gaps in the quartz crysta
<p data-desc="p @ 16px" style="font-size: 16px" contenteditable>One morning, as Gregor Samsa was waking up from anxious dreams, he discovered that in his bed he had been changed into a monstrous verminous bug. He lay on his armour-hard back and saw, as he lifted his head up a little, his brown, arched abdomen divided up into rigid bow-like sections. From this height the blanket, just about ready to slide off completely, could hardly stay in place. His numerous legs, pitifully thin in comparison to the rest of his circumference, flickered helplessly before his eyes.</p>
<p data-desc="p @ 14px" style="font-size: 14px" contenteditable>One morning, as Gregor Samsa was waking up from anxious dreams, he discovered that in his bed he had been changed into a monstrous verminous bug. He lay on his armour-hard back and saw, as he lifted his head up a little, his brown, arched abdomen divided up into rigid bow-like sections. From this height the blanket, just about ready to slide off completely, could hardly stay in place. His numerous legs, pitifully thin in comparison to the rest of his circumference, flickered helplessly before his eyes.</p>
</article>
{% include charmap.html %}
</section>
4 changes: 4 additions & 0 deletions _tasks/charmap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

ruby _tasks/generate-charmap.rb; ruby _tasks/cleanup-charmap.rb; ruby _tasks/generate-charmap-templates.rb

44 changes: 44 additions & 0 deletions _tasks/cleanup-charmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env ruby

# Cleanup charmaps

## START

# Time how long it generates
stopwatch_start = Time.now

# Get files
files = Dir.glob( '_fonts/*/*.charmap' )

# control character matching
cchar = /(?:00[0-1](?:[0-9]|[a-f]))|(?:00[8-9](?:[0-9]|[a-f]))/

# Now we loop
files.each do |charmap|
puts "Cleaning #{charmap}"

lines = File.read(charmap)

# Remove duplicate lines,
# Pad maximum zeroes 4 digits,
# Sort by alphabetical order
# Delete control characters,
lines = lines
.split( "\n" )
.uniq
.map{ |n| n.rjust( 4, "0" ) }
.sort_by{ |l| l.downcase }
.reject{ |item| item =~ cchar }
.join( "\n" )

output = File.open( charmap, "w" )
output.truncate(0)
output << lines
output.close
end

# And we're done!
stopwatch_finish = Time.now
stopwatch_delta = stopwatch_finish - stopwatch_start

puts "Finished in #{stopwatch_delta}s"
118 changes: 118 additions & 0 deletions _tasks/generate-charmap-templates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/usr/bin/env ruby

require "fileutils"

# Generate character map templates. This will be used by Jekyll to build the
# character maps

## EDIT START

# Time how long it generates
stopwatch_start = Time.now

# Get files
files = Dir.glob( '_fonts/*/*.charmap' )

# The resulting extension
ext = ".charmap"

# The dir to output to
output_dir = "_includes/charmaps"

# The "proof" dir. This will be populated with empty files that prove the
# template exists. Necessary due to jekyll's restrictions
proof_dir = "assets/charmap_template"

# How many columns the table should have
cols = 10

## EDIT END





# Make sure dirs ends in slash
output_dir << '/' unless output_dir.end_with?('/')
proof_dir << '/' unless proof_dir.end_with?('/')

# Create dirs if it doesn't exist
Dir.mkdir( output_dir ) unless File.exists?( output_dir )
Dir.mkdir( proof_dir ) unless File.exists?( proof_dir )

# clear proof files before we start
FileUtils.rm_rf( Dir.glob("#{proof_dir}/*") )

# Generate the html
def make_html( charmap, columns )
html = "<table>\n"
current_col = 0

# loop through each line
# source: http://stackoverflow.com/a/601927
charmap.split(/\r?\n|\r/).each do |line|

if ( current_col % columns == 0 )
html += "\t<tr>\n"
end

html += "\t\t<td>&#x" + line + ";</td>\n"

if ( current_col % columns == columns - 1 )
html += "\t</tr>\n"
end

current_col += 1
end

if ( current_col % columns != 0 )
html += "\t</tr>\n"
end

html += "</table>"

return html
end

# Now, the main loop
files.each do |charmap|
puts "Generating template for #{charmap}"

# Get the font name from the index.html file (ex: `Alegreya Sans`)
font_name = File
.read( File.dirname( charmap ) + '/index.html' )
.scan( /(?<=family: )(.*.)/ )[0][0]

# Get charmap name without extension (ex: `400i`)
charmap_name = File.basename( charmap, File.extname( charmap ) )

# Append charmap name with `.html` for use as template name
template_name = "#{charmap_name}.html"

# Join `output_dir` and `font_name`, with whitespaces removed
template_dir = "#{output_dir}#{font_name.gsub(/\s+/, "")}/"


html = make_html( File.read( charmap ), cols )

# Create directory if it doesn't exist
Dir.mkdir( template_dir ) unless File.exists?( template_dir )

# Create new template file
template = File.open( template_dir + "/" + template_name, "w" );

# Write the HTML
template << html

# Close file
template.close

# Create an empty file in the charmap dir that proves it exists
it_exists = File.open( "#{proof_dir}#{font_name.gsub(/\s+/, '')}-#{charmap_name}" , "w" );
end

# And we're done!
stopwatch_finish = Time.now
stopwatch_delta = stopwatch_finish - stopwatch_start

puts "Finished in #{stopwatch_delta}s"
70 changes: 70 additions & 0 deletions _tasks/generate-charmap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env ruby

# Generate character maps

# Make a .ttx file containing only the CMAP
def make_cmap_ttx( name, source )
# puts "ttx -f -o #{name} -t cmap #{source}"
system *%W(ttx -f -o #{name} -t cmap #{source})

# Check if it worked
if ! File.file?( name )
raise "Failed to create ttx cmap `#{name}`"
exit
end
end

# Return all hexadecimal values starting with `0x` without including `0x`
def grab_hex( str )
return str.scan( /(?<=0[xX])([0-9a-fA-F]+)/ )
end



## START

# Time how long it generates
stopwatch_start = Time.now

# Get files
#files = Dir.glob( '_fonts/*/400.woff' )
files = Dir.glob( '_fonts/*/*.woff' )

# The resulting extension
ext = ".charmap"

# Now we loop
files.each do |font|

font_name = File.basename( font )
font_base_name = File.basename( font, ".*" )

# Make a temporary .ttx file containing only the cmap
temp_name = File.dirname( font ) + "__#{Time.now.to_i.to_s}.cmap.ttx"
make_cmap_ttx( temp_name, font )

# Grab the temp file's contents
temp = File.read( temp_name )

# Get the Unicode values from the XML file
# Assumptions: UTF strings begin with '0x'
characters = grab_hex( temp )

# delete temp file
File.delete( temp_name )

# Make an output file with the same dir as font file
#output = File.open( font + ext, "w" );
output = File.open( "#{File.dirname( font )}/#{font_base_name}#{ext}", "w" );
output.truncate(0)

# Output the unicode values line-by-line
output << characters.join( "\n" )
output.close
end

# And we're done!
stopwatch_finish = Time.now
stopwatch_delta = stopwatch_finish - stopwatch_start

puts "Finished in #{stopwatch_delta}s"
20 changes: 20 additions & 0 deletions assets/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ section {
}
}

table {
border-collapse: collapse;

#preview .charmap & {
font-size: 1.5em;
}
}

tr {
border-bottom: 1px solid rgba(127, 127, 127, 0.5);
}

td, th {
padding: 0.75em;

&:not(:last-child) {
border-right: 1px solid rgba(127,127,127,0.2);
}
}

footer {
padding: 8em 0;

Expand Down