Skip to content

Commit

Permalink
local fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
gintama91 committed Jul 7, 2023
1 parent 9dac797 commit 32198cd
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 2 deletions.
4 changes: 4 additions & 0 deletions examples/local_fonts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Scarpe.app do
font "fonts/Pacifico.ttf"
para "Hello yayyy"
end
Binary file added fonts/Pacifico.ttf
Binary file not shown.
14 changes: 14 additions & 0 deletions lib/scarpe/font.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class Scarpe
class Font < Scarpe::Widget
display_properties :font

def initialize(font)
@font = font
super

create_display_widget
end
end
end
1 change: 1 addition & 0 deletions lib/scarpe/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@
require_relative "text_widget"
require_relative "link"
require_relative "line"
require_relative "font"
1 change: 1 addition & 0 deletions lib/scarpe/wv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@
require_relative "wv/text_widget"
require_relative "wv/link"
require_relative "wv/line"
require_relative "wv/font"
35 changes: 35 additions & 0 deletions lib/scarpe/wv/font.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require_relative "../base64"

class Scarpe
class WebviewFont < WebviewWidget
include Base64
attr_accessor :font

def initialize(properties)
@font = properties[:font]
puts "font: #{@font}"
super
end

def element
puts @font
HTML.render do |h|
h.link(href: @font, rel: "stylesheet")
h.style do
<<~CSS
@font-face {
font-family: Pacifico;
src: url("data:font/truetype;base64,#{encode_file_to_base64(@font)}") format('truetype');
}
* {
font-family: Pacifico;
}
CSS
end
# Rest of the HTML code for the element
end
end
end
end
4 changes: 2 additions & 2 deletions lib/scarpe/wv/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class Scarpe
class HTML
CONTENT_TAGS = [:div, :p, :button, :ul, :li, :textarea, :a, :strong, :em, :code, :u, :line, :span, :svg].freeze
VOID_TAGS = [:input, :img, :polygon, :path].freeze
CONTENT_TAGS = [:div, :p, :button, :ul, :li, :textarea, :a, :strong, :style, :em, :code, :u, :line, :span, :svg].freeze
VOID_TAGS = [:input, :img, :polygon, :link, :path].freeze
TAGS = (CONTENT_TAGS + VOID_TAGS).freeze

class << self
Expand Down

0 comments on commit 32198cd

Please sign in to comment.