module NSWTopo::Font::Chrome
def self.extended(instance)
def self.extended(instance) instance.start_chrome end
def glyph_length(string, attributes)
def glyph_length(string, attributes) validate attributes style = attributes.slice(*ATTRIBUTES).map do |pair| pair.join ?: end.join(?;) @text[:style] = style @text.value = string @text.width / @scale end
def start_chrome
def start_chrome @families = Set[] NSWTopo::Chrome.new("data:image/svg+xml;base64,#{Base64.encode64 SVG}").tap do |browser| @scale = browser.query_selector("rect").width @text = browser.query_selector "text" end end
def validate(attributes)
def validate(attributes) return unless family = attributes["font-family"] return unless @families.add? family @text.value = "abcdefghijklmnopqrstuvwxyz" @text[:style] = "font-family:#{family}" styled_width = @text.width @text[:style] = nil unstyled_width = @text.width log_neutral "font '#{family}' doesn't appear to be available" if styled_width == unstyled_width end