Class: Wx::Font
- Defined in:
- lib/wx/doc/gen/font.rb,
lib/wx/doc/font.rb
Overview
This class is untracked and should not be derived from nor instances extended!
A font is an object which determines the appearance of text.
Fonts are used for drawing text to a device context, and setting the appearance of a window’s text, see DC#set_font and Window#set_font. The easiest way to create a custom font is to use FontInfo object to specify the font attributes and then use wxFont::wxFont(const wxFontInfo&) constructor. Alternatively, you could start with one of the pre-defined fonts or use Window#get_font and modify the font, e.g. by increasing its size using #make_larger or changing its weight using #make_bold. This class uses reference counting and copy-on-write internally so that assignments between two instances of this class are very cheap. You can therefore use actual objects instead of pointers without efficiency problems. If an instance of this class is changed it will create its own data internally so that other instances, which previously shared the data using the reference counting, are not affected. You can retrieve the current system font settings with SystemSettings.
Category: Graphics Device Interface (GDI) Predefined objects/pointers: NULL_FONT, NORMAL_FONT, SMALL_FONT, ITALIC_FONT, SWISS_FONT
Class Method Summary collapse
-
.add_private_font(filename) ⇒ Boolean
Specify the name of a file containing a TrueType font to be made available to the current application.
- .create(*args) ⇒ Object
- .find_or_create_font(*args) ⇒ Object
-
.get_default_encoding ⇒ Wx::FontEncoding
Returns the current application’s default encoding.
-
.get_numeric_weight_of(weight) ⇒ Integer
Get the raw weight value corresponding to the given symbolic constant.
-
.set_default_encoding(encoding) ⇒ void
Sets the default font encoding.
Instance Method Summary collapse
-
#==(font) ⇒ Boolean
Equality operator.
-
#bold ⇒ Wx::Font
Returns a bold version of this font.
-
#get_base_font ⇒ Wx::Font
(also: #base_font)
Returns a font with the same face/size as the given one but with normal weight and style and not underlined nor stricken through.
-
#get_encoding ⇒ Wx::FontEncoding
(also: #encoding)
Returns the encoding of this font.
-
#get_face_name ⇒ String
(also: #face_name)
Returns the face name associated with the font, or the empty string if there is no face information.
-
#get_family ⇒ Wx::FontFamily
(also: #family)
Gets the font family if possible.
-
#get_fractional_point_size ⇒ Float
(also: #fractional_point_size)
Gets the point size as a floating number.
-
#get_native_font_info_desc ⇒ String
(also: #native_font_info_desc)
Returns the platform-dependent string completely describing this font.
-
#get_native_font_info_user_desc ⇒ String
(also: #native_font_info_user_desc)
Returns a user-friendly string for this font object.
-
#get_numeric_weight ⇒ Integer
(also: #numeric_weight)
Gets the font weight as an integer value.
-
#get_pixel_size ⇒ Wx::Size
(also: #pixel_size)
Gets the pixel size.
-
#get_point_size ⇒ Integer
(also: #point_size)
Gets the point size as an integer number.
-
#get_strikethrough ⇒ Boolean
Returns true if the font is stricken-through, false otherwise.
-
#get_style ⇒ Wx::FontStyle
(also: #style)
Gets the font style.
-
#get_underlined ⇒ Boolean
Returns true if the font is underlined, false otherwise.
-
#get_weight ⇒ Wx::FontWeight
(also: #weight)
Gets the font weight.
-
#initialize(*args) ⇒ Font
constructor
A new instance of Font.
-
#is_fixed_width ⇒ Boolean
(also: #fixed_width?)
Returns true if the font is a fixed width (or monospaced) font, false if it is a proportional one or font is invalid.
-
#is_ok ⇒ Boolean
(also: #ok?)
Returns true if this object is a valid font, false otherwise.
-
#italic ⇒ Wx::Font
Returns an italic version of this font.
-
#larger ⇒ Wx::Font
Returns a larger version of this font.
-
#make_bold ⇒ Wx::Font
Changes this font to be bold.
-
#make_italic ⇒ Wx::Font
Changes this font to be italic.
-
#make_larger ⇒ Wx::Font
Changes this font to be larger.
-
#make_smaller ⇒ Wx::Font
Changes this font to be smaller.
-
#make_strikethrough ⇒ Wx::Font
Changes this font to be stricken-through.
-
#make_underlined ⇒ Wx::Font
Changes this font to be underlined.
-
#scale(x) ⇒ Wx::Font
Changes the size of this font.
-
#scaled(x) ⇒ Wx::Font
Returns a scaled version of this font.
-
#set_encoding(encoding) ⇒ void
(also: #encoding=)
Sets the encoding for this font.
-
#set_face_name(faceName) ⇒ Boolean
(also: #face_name=)
Sets the facename for the font.
-
#set_family(family) ⇒ void
(also: #family=)
Sets the font family.
-
#set_fractional_point_size(pointSize) ⇒ void
(also: #fractional_point_size=)
Sets the font size in points.
-
#set_native_font_info(info) ⇒ Boolean
(also: #native_font_info=)
Creates the font corresponding to the given native font description string which must have been previously returned by #get_native_font_info_desc.
-
#set_native_font_info_user_desc(info) ⇒ Boolean
(also: #native_font_info_user_desc=)
Creates the font corresponding to the given native font description string and returns true if the creation was successful.
-
#set_numeric_weight(weight) ⇒ void
(also: #numeric_weight=)
Sets the font weight using an integer value.
-
#set_pixel_size(pixelSize) ⇒ void
(also: #pixel_size=)
Sets the pixel size.
-
#set_point_size(pointSize) ⇒ void
(also: #point_size=)
Sets the font size in points to an integer value.
-
#set_strikethrough(strikethrough) ⇒ void
(also: #strikethrough=)
Sets strike-through attribute of the font.
-
#set_style(style) ⇒ void
(also: #style=)
Sets the font style.
-
#set_symbolic_size(size) ⇒ void
(also: #symbolic_size=)
Sets the font size using a predefined symbolic size name.
-
#set_symbolic_size_relative_to(size, base) ⇒ void
Sets the font size compared to the base font size.
-
#set_underlined(underlined) ⇒ void
(also: #underlined=)
Sets underlining.
-
#set_weight(weight) ⇒ void
(also: #weight=)
Sets the font weight.
-
#smaller ⇒ Wx::Font
Returns a smaller version of this font.
-
#strikethrough ⇒ Wx::Font
Returns stricken-through version of this font.
-
#underlined ⇒ Wx::Font
Returns underlined version of this font.
Methods inherited from GDIObject
Methods inherited from Object
#clone, #dup, #is_same_as, #un_share
Constructor Details
#initialize ⇒ Wx::Font #initialize(font) ⇒ Wx::Font #initialize(fontInfo) ⇒ Wx::Font #initialize(pointSize, family, style, weight, underline = false, faceName = (''), encoding = Wx::FontEncoding::FONTENCODING_DEFAULT) ⇒ Wx::Font #initialize(pixelSize, family, style, weight, underline = false, faceName = (''), encoding = Wx::FontEncoding::FONTENCODING_DEFAULT) ⇒ Wx::Font #initialize(nativeInfoString) ⇒ Wx::Font
Returns a new instance of Font.
1198 |
# File 'lib/wx/doc/gen/font.rb', line 1198 def initialize(*args) end |
Class Method Details
.add_private_font(filename) ⇒ Boolean
Specify the name of a file containing a TrueType font to be made available to the current application.
This method can be used to allow this application to use the font from the given file even if it is not globally installed on the system. Under macOS this method actually doesn’t do anything other than check for the existence of the file in the “Fonts” subdirectory of the application bundle “Resources” directory. You are responsible for actually making the font file available in this directory and setting ATSApplicationFontsPath to Fonts value in your Info.plist file. See also StandardPaths#get_resources_dir. Under MSW this method must be called before any GraphicsContext objects have been created, otherwise the private font won’t be usable from them. Under Unix this method requires Pango 1.38 or later and will return false and log an error message explaining the problem if this requirement is not satisfied either at compile- or run-time. Currently this method is implemented for all major platforms (subject to having Pango 1.38 or later when running configure under Unix) and Setup::USE_PRIVATE_FONTS is always set to 0 under the other platforms, making this function unavailable at compile-time. true if the font was added and can now be used.
805 |
# File 'lib/wx/doc/gen/font.rb', line 805 def self.add_private_font(filename) end |
.self.create(pointSize, family, style, weight, underline = false, faceName = (''), encoding = Wx::FontEncoding::FONTENCODING_DEFAULT) ⇒ Wx::Font .self.create(pointSize, family, flags = Wx::FontFlag::FONTFLAG_DEFAULT, faceName = (''), encoding = Wx::FontEncoding::FONTENCODING_DEFAULT) ⇒ Wx::Font .self.create(pixelSize, family, style, weight, underline = false, faceName = (''), encoding = Wx::FontEncoding::FONTENCODING_DEFAULT) ⇒ Wx::Font .self.create(pixelSize, family, flags = Wx::FontFlag::FONTFLAG_DEFAULT, faceName = (''), encoding = Wx::FontEncoding::FONTENCODING_DEFAULT) ⇒ Wx::Font .self.create(nativeInfoString) ⇒ Wx::Font
1131 |
# File 'lib/wx/doc/gen/font.rb', line 1131 def self.create(*args) end |
.find_or_create_font(point_size, family, style, weight, underline = false, facename = '', encoding = Wx::FontEncoding::FONTENCODING_DEFAULT) ⇒ Wx::Font .find_or_create_font(font_info) ⇒ Wx::Font
27 |
# File 'lib/wx/doc/font.rb', line 27 def self.find_or_create_font(*args) end |
.get_default_encoding ⇒ Wx::FontEncoding
Returns the current application’s default encoding.
1213 |
# File 'lib/wx/doc/gen/font.rb', line 1213 def self.get_default_encoding; end |
.get_numeric_weight_of(weight) ⇒ Integer
Get the raw weight value corresponding to the given symbolic constant.
For compatibility, this function handles the values NORMAL, LIGHT and BOLD, that have values 90, 91 and 92, specially and converts them to the corresponding Wx::FONTWEIGHT_XXX weight value.
Numeric weight, between 1 and 1000.
1231 |
# File 'lib/wx/doc/gen/font.rb', line 1231 def self.get_numeric_weight_of(weight) end |
.set_default_encoding(encoding) ⇒ void
This method returns an undefined value.
Sets the default font encoding.
1222 |
# File 'lib/wx/doc/gen/font.rb', line 1222 def self.set_default_encoding(encoding) end |
Instance Method Details
#==(font) ⇒ Boolean
Equality operator.
See reference-counted object comparison for more info.
1205 |
# File 'lib/wx/doc/gen/font.rb', line 1205 def ==(font) end |
#bold ⇒ Wx::Font
Returns a bold version of this font.
812 |
# File 'lib/wx/doc/gen/font.rb', line 812 def bold; end |
#get_base_font ⇒ Wx::Font Also known as: base_font
Returns a font with the same face/size as the given one but with normal weight and style and not underlined nor stricken through.
666 |
# File 'lib/wx/doc/gen/font.rb', line 666 def get_base_font; end |
#get_encoding ⇒ Wx::FontEncoding Also known as: encoding
Returns the encoding of this font.
Note that under WXGTK the returned value is always Wx::FontEncoding::FONTENCODING_UTF8.
674 |
# File 'lib/wx/doc/gen/font.rb', line 674 def get_encoding; end |
#get_face_name ⇒ String Also known as: face_name
Returns the face name associated with the font, or the empty string if there is no face information.
682 |
# File 'lib/wx/doc/gen/font.rb', line 682 def get_face_name; end |
#get_family ⇒ Wx::FontFamily Also known as: family
Gets the font family if possible.
As described in Wx::FontFamily docs the returned value acts as a rough, basic classification of the main font properties (look, spacing). If the current font face name is not recognized by Wx::Font or by the underlying system, Wx::FontFamily::FONTFAMILY_DEFAULT is returned. Note that currently this function is not very precise and so not particularly useful. Font families mostly make sense only for font creation, see #set_family.
692 |
# File 'lib/wx/doc/gen/font.rb', line 692 def get_family; end |
#get_fractional_point_size ⇒ Float Also known as: fractional_point_size
Gets the point size as a floating number.
732 |
# File 'lib/wx/doc/gen/font.rb', line 732 def get_fractional_point_size; end |
#get_native_font_info_desc ⇒ String Also known as: native_font_info_desc
Returns the platform-dependent string completely describing this font.
Returned string is always non-empty unless the font is invalid (in which case an assert is triggered). Note that the returned string is not meant to be shown or edited by the user: a typical use of this function is for serializing in string-form a Wx::Font object.
702 |
# File 'lib/wx/doc/gen/font.rb', line 702 def get_native_font_info_desc; end |
#get_native_font_info_user_desc ⇒ String Also known as: native_font_info_user_desc
Returns a user-friendly string for this font object.
Returned string is always non-empty unless the font is invalid (in which case an assert is triggered). The string does not encode all Wx::Font infos under all platforms; e.g. under WXMSW the font family is not present in the returned string. Some examples of the formats of returned strings (which are platform-dependent) are in #set_native_font_info_user_desc.
713 |
# File 'lib/wx/doc/gen/font.rb', line 713 def get_native_font_info_user_desc; end |
#get_numeric_weight ⇒ Integer Also known as: numeric_weight
Gets the font weight as an integer value.
See Wx::FontWeight for a list of valid weight identifiers and their corresponding integer value.
780 |
# File 'lib/wx/doc/gen/font.rb', line 780 def get_numeric_weight; end |
#get_pixel_size ⇒ Wx::Size Also known as: pixel_size
Gets the pixel size.
Note that under WXMSW if you passed to #set_pixel_size (or to the ctor) a Size object with a null width value, you’ll get a null width in the returned object.
740 |
# File 'lib/wx/doc/gen/font.rb', line 740 def get_pixel_size; end |
#get_point_size ⇒ Integer Also known as: point_size
Gets the point size as an integer number.
This function is kept for compatibility reasons. New code should use #get_fractional_point_size and support fractional point sizes.
724 |
# File 'lib/wx/doc/gen/font.rb', line 724 def get_point_size; end |
#get_strikethrough ⇒ Boolean
Returns true if the font is stricken-through, false otherwise.
763 |
# File 'lib/wx/doc/gen/font.rb', line 763 def get_strikethrough; end |
#get_style ⇒ Wx::FontStyle Also known as: style
Gets the font style.
See Wx::FontStyle for a list of valid styles.
748 |
# File 'lib/wx/doc/gen/font.rb', line 748 def get_style; end |
#get_underlined ⇒ Boolean
Returns true if the font is underlined, false otherwise.
756 |
# File 'lib/wx/doc/gen/font.rb', line 756 def get_underlined; end |
#get_weight ⇒ Wx::FontWeight Also known as: weight
Gets the font weight.
See Wx::FontWeight for a list of valid weight identifiers.
770 |
# File 'lib/wx/doc/gen/font.rb', line 770 def get_weight; end |
#is_fixed_width ⇒ Boolean Also known as: fixed_width?
Returns true if the font is a fixed width (or monospaced) font, false if it is a proportional one or font is invalid.
Note that this function under some platforms is different from just testing for the font family being equal to Wx::FontFamily::FONTFAMILY_TELETYPE because native platform-specific functions are used for the check (resulting in a more accurate return value).
787 |
# File 'lib/wx/doc/gen/font.rb', line 787 def is_fixed_width; end |
#is_ok ⇒ Boolean Also known as: ok?
Returns true if this object is a valid font, false otherwise.
792 |
# File 'lib/wx/doc/gen/font.rb', line 792 def is_ok; end |
#italic ⇒ Wx::Font
Returns an italic version of this font.
819 |
# File 'lib/wx/doc/gen/font.rb', line 819 def italic; end |
#larger ⇒ Wx::Font
Returns a larger version of this font.
The font size is multiplied by 1.2, the factor of 1.2 being inspired by the W3C CSS specification.
828 |
# File 'lib/wx/doc/gen/font.rb', line 828 def larger; end |
#make_bold ⇒ Wx::Font
Changes this font to be bold.
858 |
# File 'lib/wx/doc/gen/font.rb', line 858 def make_bold; end |
#make_italic ⇒ Wx::Font
Changes this font to be italic.
865 |
# File 'lib/wx/doc/gen/font.rb', line 865 def make_italic; end |
#make_larger ⇒ Wx::Font
Changes this font to be larger.
The font size is multiplied by 1.2, the factor of 1.2 being inspired by the W3C CSS specification.
874 |
# File 'lib/wx/doc/gen/font.rb', line 874 def make_larger; end |
#make_smaller ⇒ Wx::Font
Changes this font to be smaller.
The font size is divided by 1.2, the factor of 1.2 being inspired by the W3C CSS specification.
883 |
# File 'lib/wx/doc/gen/font.rb', line 883 def make_smaller; end |
#make_strikethrough ⇒ Wx::Font
Changes this font to be stricken-through.
Currently stricken-through fonts are only supported in WXMSW, WXGTK, and WXOSX.
897 |
# File 'lib/wx/doc/gen/font.rb', line 897 def make_strikethrough; end |
#make_underlined ⇒ Wx::Font
Changes this font to be underlined.
890 |
# File 'lib/wx/doc/gen/font.rb', line 890 def make_underlined; end |
#scale(x) ⇒ Wx::Font
Changes the size of this font.
The font size is multiplied by the given factor (which may be less than 1 to create a smaller version of the font).
907 |
# File 'lib/wx/doc/gen/font.rb', line 907 def scale(x) end |
#scaled(x) ⇒ Wx::Font
Returns a scaled version of this font.
The font size is multiplied by the given factor (which may be less than 1 to create a smaller version of the font).
917 |
# File 'lib/wx/doc/gen/font.rb', line 917 def scaled(x) end |
#set_encoding(encoding) ⇒ void Also known as: encoding=
This method returns an undefined value.
Sets the encoding for this font.
Note that under WXGTK this function has no effect (because the underlying Pango library always uses Wx::FontEncoding::FONTENCODING_UTF8).
925 |
# File 'lib/wx/doc/gen/font.rb', line 925 def set_encoding(encoding) end |
#set_face_name(faceName) ⇒ Boolean Also known as: face_name=
Sets the facename for the font.
To avoid portability problems, don't rely on a specific face, but specify the font family instead (see Wx::FontFamily and #set_family).
true if the given face name exists; if the face name doesn’t exist in the user’s system then the font is invalidated (so that #is_ok will return false) and false is returned.
941 |
# File 'lib/wx/doc/gen/font.rb', line 941 def set_face_name(faceName) end |
#set_family(family) ⇒ void Also known as: family=
This method returns an undefined value.
Sets the font family.
As described in Wx::FontFamily docs the given family value acts as a rough, basic indication of the main font properties (look, spacing). Note that changing the font family results in changing the font face name.
952 |
# File 'lib/wx/doc/gen/font.rb', line 952 def set_family(family) end |
#set_fractional_point_size(pointSize) ⇒ void Also known as: fractional_point_size=
This method returns an undefined value.
Sets the font size in points.
The point size is defined as 1/72 of the Anglo-Saxon inch (25.4 mm): it is approximately 0.0139 inch or 352.8 um.
1006 |
# File 'lib/wx/doc/gen/font.rb', line 1006 def set_fractional_point_size(pointSize) end |
#set_native_font_info(info) ⇒ Boolean Also known as: native_font_info=
Creates the font corresponding to the given native font description string which must have been previously returned by #get_native_font_info_desc.
If the string is invalid, font is unchanged. This function is typically used for de-serializing a Wx::Font object previously saved in a string-form. true if the creation was successful.
962 |
# File 'lib/wx/doc/gen/font.rb', line 962 def set_native_font_info(info) end |
#set_native_font_info_user_desc(info) ⇒ Boolean Also known as: native_font_info_user_desc=
Creates the font corresponding to the given native font description string and returns true if the creation was successful.
Unlike #set_native_font_info, this function accepts strings which are user-friendly. Examples of accepted string formats are:
platform generic syntax example
WXGTK2 [underlined] [strikethrough] [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]
Monospace bold 10
WXMSW [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]
Tahoma 10 WINDOWS-1252
Todoadd an example for WXOSX
For more detailed information about the allowed syntaxes you can look at the documentation of the native API used for font-rendering (e.g. pango_font_description_from_string under GTK, although notice that it doesn’t support the “underlined” and “strikethrough” attributes and so those are handled by wxWidgets itself). Note that unlike #set_native_font_info, this function doesn’t always restore all attributes of the Wx::Font object under all platforms; e.g. on WXMSW the font family is not restored (because GetNativeFontInfoUserDesc doesn’t return it on WXMSW). If you want to serialize/deserialize a font in string form, you should use #get_native_font_info_desc and #set_native_font_info instead.
988 |
# File 'lib/wx/doc/gen/font.rb', line 988 def set_native_font_info_user_desc(info) end |
#set_numeric_weight(weight) ⇒ void Also known as: numeric_weight=
This method returns an undefined value.
Sets the font weight using an integer value.
See Wx::FontWeight for a list of valid weight identifiers and their corresponding integer value.
1078 |
# File 'lib/wx/doc/gen/font.rb', line 1078 def set_numeric_weight(weight) end |
#set_pixel_size(pixelSize) ⇒ void Also known as: pixel_size=
This method returns an undefined value.
Sets the pixel size.
The height parameter of pixelSize must be positive while the width parameter may also be zero (to indicate that you’re not interested in the width of the characters: a suitable width will be chosen for best rendering). This feature (specifying the font pixel size) is directly supported only under WXMSW and WXGTK currently; under other platforms a font with the closest size to the given one is found using binary search (this maybe slower).
1016 |
# File 'lib/wx/doc/gen/font.rb', line 1016 def set_pixel_size(pixelSize) end |
#set_point_size(pointSize) ⇒ void Also known as: point_size=
This method returns an undefined value.
Sets the font size in points to an integer value.
This is a legacy version of the function only supporting integer point sizes. It can still be used, but to avoid unnecessarily restricting the font size in points to integer values, consider using the new (added in wxWidgets 3.1.2) #set_fractional_point_size function instead.
996 |
# File 'lib/wx/doc/gen/font.rb', line 996 def set_point_size(pointSize) end |
#set_strikethrough(strikethrough) ⇒ void Also known as: strikethrough=
This method returns an undefined value.
Sets strike-through attribute of the font.
Currently stricken-through fonts are only supported in WXMSW, WXGTK, and WXOSX.
1060 |
# File 'lib/wx/doc/gen/font.rb', line 1060 def set_strikethrough(strikethrough) end |
#set_style(style) ⇒ void Also known as: style=
This method returns an undefined value.
Sets the font style.
1025 |
# File 'lib/wx/doc/gen/font.rb', line 1025 def set_style(style) end |
#set_symbolic_size(size) ⇒ void Also known as: symbolic_size=
This method returns an undefined value.
Sets the font size using a predefined symbolic size name.
This function allows changing font size to be (very) large or small compared to the standard font size.
1034 |
# File 'lib/wx/doc/gen/font.rb', line 1034 def set_symbolic_size(size) end |
#set_symbolic_size_relative_to(size, base) ⇒ void
This method returns an undefined value.
Sets the font size compared to the base font size.
This is the same as #set_symbolic_size except that it uses the given font size as the normal font size instead of the standard font size.
1043 |
# File 'lib/wx/doc/gen/font.rb', line 1043 def set_symbolic_size_relative_to(size, base) end |
#set_underlined(underlined) ⇒ void Also known as: underlined=
This method returns an undefined value.
Sets underlining.
1051 |
# File 'lib/wx/doc/gen/font.rb', line 1051 def set_underlined(underlined) end |
#set_weight(weight) ⇒ void Also known as: weight=
This method returns an undefined value.
Sets the font weight.
1069 |
# File 'lib/wx/doc/gen/font.rb', line 1069 def set_weight(weight) end |
#smaller ⇒ Wx::Font
Returns a smaller version of this font.
The font size is divided by 1.2, the factor of 1.2 being inspired by the W3C CSS specification.
837 |
# File 'lib/wx/doc/gen/font.rb', line 837 def smaller; end |
#strikethrough ⇒ Wx::Font
Returns stricken-through version of this font.
Currently stricken-through fonts are only supported in WXMSW, WXGTK, and WXOSX.
851 |
# File 'lib/wx/doc/gen/font.rb', line 851 def strikethrough; end |
#underlined ⇒ Wx::Font
Returns underlined version of this font.
844 |
# File 'lib/wx/doc/gen/font.rb', line 844 def underlined; end |