mirror of
https://github.com/gamecreature/QtAwesome.git
synced 2025-12-17 04:04:35 +03:00
Font Awesome 6
This commit is contained in:
22
tools/QtAwesomeEnumGenerated.h.erb
Normal file
22
tools/QtAwesomeEnumGenerated.h.erb
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace fa {
|
||||
enum fa_common_icons : uint16_t {
|
||||
<% icons_common.each_with_index do |(name, unicode), index| -%>
|
||||
<%= id_name(name) %> = <%= "0x#{unicode}" -%><%= index < icons_common.length - 1 ? ',' : '' %>
|
||||
<% end %>
|
||||
};
|
||||
|
||||
|
||||
enum fa_brand_icons : uint16_t {
|
||||
<% icons_brands.each_with_index do |(name, unicode), index| -%>
|
||||
<%= id_name(name) %> = <%= "0x#{unicode}" -%><%= index < icons_brands.length - 1 ? ',' : '' %>
|
||||
<% end %>
|
||||
};
|
||||
|
||||
#ifdef FONT_AWESOME_PRO
|
||||
enum fa_pro_icons : uint16_t {
|
||||
<% icons_pro.each_with_index do |(name, unicode), index| -%>
|
||||
<%= id_name(name) %> = <%= "0x#{unicode}" -%><%= index < icons_pro.length - 1 ? ',' : '' %>
|
||||
<% end %>
|
||||
};
|
||||
#endif
|
||||
}
|
||||
26
tools/QtAwesomeStringGenerated.h.erb
Normal file
26
tools/QtAwesomeStringGenerated.h.erb
Normal file
@@ -0,0 +1,26 @@
|
||||
static const fa::QtAwesomeNamedIcon faCommonIconArray[] = {
|
||||
<% icons_common.each_with_index do |(name, _unicode), index| -%>
|
||||
{ <%= string_name(name) %>, <%= namespaced_id_name(name) %> } <%= index < icons_common.length - 1 ? ',' : '' %>
|
||||
<% end %>
|
||||
};
|
||||
|
||||
static const fa::QtAwesomeNamedIcon faBrandsIconArray[] = {
|
||||
<% icons_brands.each_with_index do |(name, _unicode), index| -%>
|
||||
{ <%= string_name(name) %>, <%= namespaced_id_name(name) %> } <%= index < icons_brands.length - 1 ? ',' : '' %>
|
||||
<% end %>
|
||||
};
|
||||
|
||||
#ifdef FONT_AWESOME_PRO
|
||||
static const fa::QtAwesomeNamedIcon faProIconArray[] = {
|
||||
<% icons_pro.each_with_index do |(name, _unicode), index| -%>
|
||||
{ <%= string_name(name) %>, <%= namespaced_id_name(name) %> } <%= index < icons_pro.length - 1 ? ',' : '' %>
|
||||
<% end %>
|
||||
};
|
||||
#else
|
||||
|
||||
static const fa::QtAwesomeNamedIcon faRegularFreeIconArray[] = {
|
||||
<% icons_regular_free.each_with_index do |(name, _unicode), index| -%>
|
||||
{ <%= string_name(name) %>, <%= namespaced_id_name(name) %> } <%= index < icons_pro.length - 1 ? ',' : '' %>
|
||||
<% end %>
|
||||
};
|
||||
#endif
|
||||
78
tools/build_headers.rb
Executable file
78
tools/build_headers.rb
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# This script is used to extract the font information from the FontAwesome icons.json file
|
||||
# It extracts all font definitions/names and generated the included header files,
|
||||
# automating the process for generating the font names
|
||||
#
|
||||
# It generates the following files:
|
||||
# - QtAwesomEnumGenerated.h
|
||||
# - QtAwesomeGenerated.h
|
||||
#
|
||||
# To use it make sure the fontawesome icons.json is place in the the QtAwesome/fonts/pro/metadata folder
|
||||
require 'erb'
|
||||
require 'json'
|
||||
|
||||
class Icons
|
||||
attr_reader :icons_common,
|
||||
:icons_brands,
|
||||
:icons_pro,
|
||||
:icons_regular_free
|
||||
|
||||
def initialize(icon_file)
|
||||
@icons_common = {}
|
||||
@icons_brands = {}
|
||||
@icons_pro = {}
|
||||
@icons_regular_free = {}
|
||||
build_maps(JSON.parse(File.read(icon_file)))
|
||||
end
|
||||
|
||||
def id_name(str)
|
||||
"fa_#{str.downcase.gsub(/[^a-z0-9_]/, '_')}"
|
||||
end
|
||||
|
||||
def namespaced_id_name(str)
|
||||
"fa::#{id_name(str)}"
|
||||
end
|
||||
|
||||
def string_name(str)
|
||||
name = str.gsub("\"", "\\\"")
|
||||
"\"#{name}\""
|
||||
end
|
||||
|
||||
def build_maps(icons)
|
||||
icons.each do |key, data|
|
||||
if data['free'].length > 0
|
||||
if data['free'].first == 'brands'
|
||||
@icons_brands[key] = data['unicode']
|
||||
else
|
||||
@icons_regular_free[key] = data['unicode'] if data['free'].include?('regular')
|
||||
@icons_common[key] = data['unicode']
|
||||
end
|
||||
end
|
||||
|
||||
if data['free'].length == 0
|
||||
@icons_pro[key] = data['unicode']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def generate(template)
|
||||
ERB.new(template, trim_mode: '-').result(binding)
|
||||
end
|
||||
end
|
||||
|
||||
icon_file = ARGV[1] || "#{__dir__}/../QtAwesome/fonts/pro/metadata/icons.json"
|
||||
output_path = "#{__dir__}/../QtAwesome"
|
||||
|
||||
source_names = [
|
||||
'QtAwesomeEnumGenerated.h',
|
||||
'QtAwesomeStringGenerated.h'
|
||||
]
|
||||
|
||||
icons = Icons.new(icon_file)
|
||||
|
||||
# generate the templates
|
||||
source_names.each do |source_name|
|
||||
result = icons.generate(File.read("#{__dir__}/#{source_name}.erb"))
|
||||
File.write("#{output_path}/#{source_name}", result)
|
||||
end
|
||||
Reference in New Issue
Block a user