How to set bold label with ObjectSetText in MQL - mql4

Is there a way to set bold text using ObjectSetText() function in MQL4.
Should a font name be for example "Arial Bold" or can I set a path to the font .ttf-file?
If a path option is possible, is that path relative or absolute?

ObjectSetText() uses O/S-registered fonts & only limited controls
as one may test on GUI panels, MQL4 operations do not have full type-setting font-manipulation controls available via code
( this is all about trading, isn't it? )
Check what fonts are available from your O/S:
( or from used Docker/WINE thin-wrapper container )
So in MQL4 code there will thus simply be a string-typed or #define-ed literal specification of the font name and one may additionally set aFontSIZE + aFontCOLOUR attribute(s)
#define clrSignalLABEL clrAqua // LITERAL-way
#define iLabelFontSIZE 24
string signalTextFONT 'Times New Roman'; // STRING-way

input bool Font_Bold = true;
string FB;
int init()
{
if(Font_Bold == true)
{
FB = "Arial Bold";
}
else
{
FB = "Arial";
}
}
ObjectSetText("name", Text, FontSize, FB, FontColor);

Related

iOS using custom Arabic/Cyrillic fonts automatically

I'm trying to learn if it is possible to use a custom Arabic and Cyrillic fonts without having to do a switch/if-else on the user's language setting.
I can successfully use my custom font in the app. I'd like to supply a custom Ar/Cy font the same way, and I know I could build it into the app. If I have my font SpecialFont.otf and also supply SpecialFont-CY.otf how would the OS know to use SpecialFontCY.otf when the user is using a Cyrillic language? Ideally the OS will know the user's primary font and would be able to select a font that matches/includes the correct glyphs for the language.
PS. this is not a question on how to use a custom font, I can do that. I want to know how to supply multiple fonts for various languages to fully support the world without writing code like this:
if NSLocale.preferredLanguages.first == "Arabic"
let myFont = UIFont(name:"SpecialFont-AR", size: 17)
else if NSLocale.preferredLanguages.first == "Russian"
let myFont = UIFont(name:"SpecialFont-CY", size: 17)
...etc
Rather than using a UIFont, you want a UIFontDescriptor. With that you can set the font attribute cascadeList, which tells the system what order to select fonts based on glyph availability (i.e. look in SpecialFont, but if you can't find a glyph for ب, try SpecialFont-CY, and then SpecialFont-AR).
The point of a cascade list is to select the correct font for a given glyph. This way, if a string contains Cyrillic, Arabic, and Latin mixed together, it'll still work fine.
For example:
// Start with your base font
let font = UIFont(name:"SpecialFont", size: 17)!
// Create the ordered cascade list.
let cascadeList = [
UIFontDescriptor(fontAttributes: [.name: "SpecialFont-AR"]),
UIFontDescriptor(fontAttributes: [.name: "SpecialFont-CY"]),
]
// Create a new font descriptor based on your existing font, but adding the cascade list
let cascadedFontDescriptor = font.fontDescriptor.addingAttributes([.cascadeList: cascadeList])
// Make a new font base on this descriptor
let cascadedFont = UIFont(descriptor: cascadedFontDescriptor, size: font.pointSize)
This is covered in detail in Creating Apps for a Global Audience (WWDC 2018).
No you can't, but you can define a simple extension to DRY your code:
extension UIFont {
static func preferred(ofSize size: CGFloat) -> UIFont{
switch NSLocale.preferredLanguages.first {
case "Arabic": return UIFont(name:"SpecialFont-AR", size: size)!
case "Russian": return UIFont(name:"SpecialFont-CY", size: size)!
default: return UIFont.systemFont(ofSize: size) // etc.
}
}
}
Now all you have to do is:
let myFont = UIFont.preferred(ofSize: 17)
You will need to check this somehow in order to determine what is the right language to set.
If you don't want to use if/else syntax, you can use Ternary Conditional Operator.
let myFont = (NSLocale.preferredLanguages.first == "Arabic") ? UIFont(name:"SpecialFont-AR", size: 17) : UIFont(name:"SpecialFont-CY", size: 17)
Or more readable, like this:
let fontName = (NSLocale.preferredLanguages.first == "Arabic") ? "SpecialFont-AR" : "SpecialFont-CY"
let myFont = UIFont(name: fontName, size: 17)

Unbolding a UIFontDescriptor

I'm using dynamic type in an application and have scenarios where I want to change the font's appearance, for example making it italic or unbolding it. Adding a style is easy enough:
UIFontDescriptor *descriptor = [[UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleHeadline]
fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic];
UIFont *font = [UIFont fontWithDescriptor:descriptor size:descriptor.pointSize];
There's no clear mechanism for removing a style however. I could try adjusting the attributes but they look even more daunting, with completely undocumented API's:
Regular Headline: {
NSCTFontUIUsageAttribute = UICTFontTextStyleHeadline;
NSFontNameAttribute = ".AppleSystemUIHeadline";
NSFontSizeAttribute = 17;
}
Italic Headline: {
NSCTFontUIUsageAttribute = UICTFontTextStyleItalicHeadline;
NSFontNameAttribute = ".AppleSystemUIItalicHeadline";
NSFontSizeAttribute = 17;
}
Is there another avenue I'm missing? I could use [UIFont systemFontWithSize:descriptor.pointSize] but I don't want to lose whatever drawing rules are provided by dynamic type.
The fontDescriptorWithSymbolicTraits: method is actually capable of doing what you want, with the exception of some edge cases in font trait support among the built-in semantic text styles. The key concept here is that this method replaces all symbolic traits on the previous descriptor with the new trait(s). The documentation is a bit wishy-washy on this simply stating that the new traits "take precedence over" the old.
Bitwise operations are used to add and remove specific traits, but it appears that special care is required when working with a descriptor generated by preferredFontDescriptorWithTextStyle:. Not all fonts support all traits. The headline font, for instance, is weighted according to the user's preferred content size and even if you can strip the descriptor of its bold trait, the matching UIFont will be bold. Unfortunately, this is not documented anywhere so the discovery of any additional nuances is left as an exercise for the reader.
The following example illustrates these issues:
// Start with a system font, in this case the headline font
// bold: YES italic: NO
UIFontDescriptor * originalDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleHeadline];
NSLog(#"originalDescriptor bold: %d italic: %d",
isBold(originalDescriptor), isItalic(originalDescriptor));
// Try to set the italic trait. This may not be what you expected; the
// italic trait is not added. On a normal UIFontDescriptor the italic
// trait would have been set and the bold trait unset.
// Ultimately it seems that there is no variant of the headline font that
// is italic but not bold.
// bold: YES italic: NO
UIFontDescriptor * italicDescriptor = [originalDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic];
NSLog(#"italicDescriptor bold: %d italic: %d",
isBold(italicDescriptor), isItalic(italicDescriptor));
// The correct way to make this font descriptor italic (and coincidentally
// the safe way to make any other descriptor italic without discarding its
// other traits) would be as follows:
// bold: YES italic: YES
UIFontDescriptor * boldItalicDescriptor = [originalDescriptor fontDescriptorWithSymbolicTraits:(originalDescriptor.symbolicTraits | UIFontDescriptorTraitItalic)];
NSLog(#"boldItalicDescriptor bold: %d italic: %d",
isBold(boldItalicDescriptor), isItalic(boldItalicDescriptor));
// Your intention was to remove bold without affecting any other traits, which
// is also easy to do with bitwise logic.
// Using the originalDescriptor, remove bold by negating it then applying
// a logical AND to filter it out of the existing traits.
// bold: NO italic: NO
UIFontDescriptor * nonBoldDescriptor = [originalDescriptor fontDescriptorWithSymbolicTraits:(originalDescriptor.symbolicTraits & ~UIFontDescriptorTraitBold)];
NSLog(#"nonBoldDescriptor bold: %d italic: %d",
isBold(nonBoldDescriptor), isItalic(nonBoldDescriptor));
// Seems like it worked, EXCEPT there is no font that matches. Turns out
// there is no regular weight alternative for the headline style font.
// To confirm, test with UIFontDescriptorTraitsAttribute as the mandatory
// key and you'll get back a nil descriptor.
// bold: YES italic: NO
nonBoldDescriptor = [nonBoldDescriptor matchingFontDescriptorsWithMandatoryKeys:nil].firstObject;
NSLog(#"nonBoldDescriptor bold: %d italic: %d",
isBold(nonBoldDescriptor), isItalic(nonBoldDescriptor));
FYI, the isBold and isItalic functions used above for the sake of brevity could be implemented as follows:
BOOL isBold(UIFontDescriptor * fontDescriptor)
{
return (fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold) != 0;
}
BOOL isItalic(UIFontDescriptor * fontDescriptor)
{
return (fontDescriptor.symbolicTraits & UIFontDescriptorTraitItalic) != 0;
}

get font-weight of an uitextview

I want to resize the font-size in some UITextViews. That works fine with an outlet collection and this code:
for (UITextView *view in self.viewsToResize) {
if ([view respondsToSelector:#selector(setFont:)]) {
[view setFont:[UIFont systemFontOfSize:view.font.pointSize + 5]];
}
}
But my problem is, that not every textView uses the systemFont in normal weight, some of them are in bold weight. Is it possible to get the font-weight? With a po view.font in the debug area I can see everything I need:
$11 = 0x0c596ea0 <UICFFont: 0xc596ea0> font-family: "Helvetica"; font-weight: normal; font-style: normal; font-size: 12px
But how can I access the font-weight?
Using a second outlet collection for the bold views could solve my problem. But I'm wondering that I found nothing to get only the font-weight.
I have figured out how to get the font weights, you have to spelunk down to Core Text:
let ctFont = font as CTFont
let traits = CTFontCopyTraits(ctFont)
let dict = traits as Dictionary
if let weightNumber = dict[kCTFontWeightTrait] as? NSNumber {
print(weightNumber.doubleValue)
}
Enjoy!
UIFont does not have a bold/italic/... property, so you will have to rely on the font name only.
This will be a problem if you don't know which fonts will be used.
In the case you know that you will use eg. only Helvetica you can try this:
UIFont *font = textview.font;
if([font.fontName isEqualToString:#"Helvetica-Bold"])
NSLog(#"It's Bold!");
Alternatively you can search font.fontName for the word "bold"/"medium"/"light" etc., but that's not a guarantee you will get something from every available font:
if ([font.fontName rangeOfString:#"bold" options:NSCaseInsensitiveSearch].location == NSNotFound) {
NSLog(#"font is not bold");
} else {
NSLog(#"font is bold!");
}
// if font.fontName contains "medium"....
// if font.fontName contains "italic"....
Check http://iosfonts.com/ for the available font names.
But my problem is, that not every textView uses the systemFont in
normal weight, some of them are in bold weight.
If you want to use Bold System Font then you can simply use
[UIFont boldSystemFontOfSize:15.0];
However, I am still thinking of that special case in which you need to use font-weight.
Update :
There is nothing in the UIFont Class using which you can get font-weight directly. You can take a look at UIFont Class Reference.
Only thing that you can do is to get the font-name and try to find out the "bold" sub-string in the font name. If any match found that means font-weight of that specific font is "bold".
But, still this is not the most efficient method.
You can get a UIFontDescriptor for a font using the fontDescriptor method. Then you get the fontAttributes dictionary of the UIFontDescriptor, get the UIFontDescriptorTraitsAttribute from the dictionary which returns another dictionary, then read the UIFontWeightTrait from that dictionary. Not tested.
Now it's tested: Doesn't work. fontAttributes always returns a dictionary with two keys for font name and font size, and that's it. I suppose "this doesn't work" is also an answer when something should work according to the documentation...
You can try symbolicTraits, but that's not useful either: It returns "bold" only if the whole font family is bold.

Is this possible to change the font of whole application in jquery mobile

In my app there is field change font Actually using that user can change the font of whole application.Is this possible actually if i have 100 field in my project (may be different different font size on every page ).How can user change the font size .so that it can reflect on whole application.As I goggled i found that there is functionality of zoom in and zoom out .It is not a good way to do that .? is there any way to change font of whole application?
You can create a style dynamically and apply it to all elements within body.
Demo
$('#select_font').on('change', function () {
var style;
var font = $(this).val();
if ($('head').find('style.font').length === 0) {
style = $('<style class="font">.font { font-size: ' + font + ' !important; }</style>');
$('head').append(style);
$('body *').addClass('font');
} else {
$('body *').removeClass('font');
$('style.font').empty();
style = '.font { font-size: ' + font + ' !important; }';
$('style.font').append(style);
$('body *').addClass('font');
}
});
This article shows a nice way of doing it in CSS only.
http://joshnh.com/2011/07/26/are-you-using-ems-with-your-media-queries/
Key is to only using em, then you can switch font size globally by changing the base for em.

How to set a font to LabelField text in Blackberry?

I don't know how to apply font style to a text in a LabelField in Blackberry.
You can just use LabelField.setFont. If you don't do this explicitly on the label field, the field will use whatever font is used by its manager (and so on upward up the hierarchy).
There are a couple of ways to get a font. One is to derive one from an existing font (in this case I'm getting a bold version of the default font):
LabelField labelField = new LabelField("Hello World");
Font myFont = Font.getDefault().derive(Font.BOLD, 9, Ui.UNITS_pt);
labelField.setFont(myFont);
The other is to get a specific font family and derive a font from that (here getting a 12 pt italic font):
LabelField labelField = new LabelField("Hello World");
FontFamily fontFamily = FontFamily.forName("BBCasual");
Font myFont = fontFamily.derive(Font.ITALIC, 12, Ui.UNITS_pt);
labelField.setFont(myFont);
A couple of things to note: I used UNITS_pt (points) instead of UNITS_px (pixels). This is a good idea generally since BlackBerry devices vary quite a bit in screen size and resolution (DPI) and using points will give you a more consistent look across devices, instead of having your text look tiny on a Bold or 8900 (or huge on a Curve or Pearl).
Also in the second example, forName can throw a ClassCastException which you have to catch (it's a checked exception) but is never actually thrown according to the Javadocs, if you specify an unknown name, it'll fall back to another font family.
Here's a post which has a ResponseLabelField that extends LabelField and shows how to set the font:
http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=37988
Here's a quick code snippet for you:
LabelField displayLabel = new LabelField("Test", LabelField.FOCUSABLE)
{
protected void paintBackground(net.rim.device.api.ui.Graphics g)
{
g.clear();
g.getColor();
g.setColor(Color.CYAN);
g.fillRect(0, 0, Display.getWidth(), Display.getHeight());
g.setColor(Color.BLUE);
}
};
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font font = fontFamily[1].getFont(FontFamily.CBTF_FONT, 8);
displayLabel.setFont(font);
Someone correct me if I'm wrong, but I believe different fonts are chosen by using a different index into the fontFamily array.
EDIT: And here's a test app you can use to switch between fonts: http://blackberry-digger.blogspot.com/2009/04/how-to-change-fonts-in-blackberry.html

Resources