Xamarin Forms Font Icons displaying wrong symbols - xamarin

In development I have no issues with FontAwesome icons used within my app, however, as soon as other devices install it in testing/production the icons appear incorrectly. I will show screenshots below.
I really appreciate anyone giving some input to this, it's quite problematic to the point where I am considering going back to images.
It seems they map incorrectly on new device installations. Sometimes I get weird Chinese characters instead. The below is just one example, this behaviour happens across the board.
Font Class
[assembly: ExportFont("fontello.ttf", Alias = "Fontello")]
namespace TestApp.Fonts
{
// cut class short for readability but it has a lot more icon codes
static class FontelloFont
{
public const string MapMarkerO = "\ue82c"; // This is the icon used in the photo of how it should look like
public const string OccupierO = "\ue832"; // This is the icon that appears in place of whats above when it shouldn't
Usage
<Label Text="{x:Static fonts:FontelloFont.MapMarkerO}"
FontSize="35"
FontFamily="Fontello"/>
What should appear
What actually appears

Related

How to properly position a QGraphicsTextItem on a QGraphicsScene

The probelm I have is that I am trying to position a QGraphicsTextItem on a specific location of my QGraphicsScene , to be precise in the center of the speedometer below. But nothing I tried seems to work properly. Despite I clearly provided the coordinates I want the QGraphicsTextItem, it still anchored on top-left as shown below:
Below the snippet of code:
speedwidget.cpp
SpeedWidget::SpeedWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::SpeedWidget)
{
ui->setupUi(this);
mScene = new Scene(this);
ui->graphicsView->setScene(mScene);
io = new QGraphicsTextItem;
io->setPos(210,240);
QFont *f = new QFont;
f->setPointSize(18);
io->setFont(*f);
mScene->addText("Odometer :")->setDefaultTextColor(Qt::red);
mScene->addItem(io);
}
speedwidget.h
class SpeedWidget : public QWidget
{
Q_OBJECT
public:
SpeedWidget(QWidget *parent = nullptr);
~SpeedWidget();
private:
Ui::SpeedWidget *ui;
Scene *mScene;
QGraphicsTextItem *io;
};
#endif // SPEEDWIDGET_H
What I tried so far to solve the problem was:
I consulted this post which explained the idea but I don't need to change the background color in this example.
This one had a good snippet, but I am not trying to highlight the color. I am only trying to position the text on a specific location.
If I change io->setPos(210,240); and give different numbers, I still see it anchored on top-left.
Thanks for pointing to the right direction for solving this issue.
The Qt Graphics View framework implements a parent-child mechanism. Simply make your QGraphicsTextItem become a child of your odometer's dial item. From then on, your text label's position will be relative to the one of the dial:
io = new QGraphicsTextItem(this);
// Position text item so that it's centered on the dial
...
Furthermore, note that this line:
mScene->addText("Odometer :")->setDefaultTextColor(Qt::red);
Means that you create yet another text item. A pointer to the newly created item is being returned. Either use & retain that one or use the one that you explicitly created with the new expression.
Furthermore you might want to reconsider your choice of using a QGraphicsScene for one simple "widget". While the Qt graphics framework is not necessarily heavy, it certainly brings quite a lot of overhead for just rendering an odometer.
You can simply overwrite the QWidget::paint() function in your SpeedWidget subclass and render everything using QPainter. That will be a lot lighter and also a lot less hassle.

Should I use different sized icons for iOS and Android in a forms application?

I have a forms application with a tab bar. For the iOS I created these icons:
ionicons_2-0-1_ios-pause-outline_25.png
ionicons_2-0-1_ios-pause-outline_25#2x.png
ionicons_2-0-1_ios-pause-outline_2523x.png
They are sized 25*25, 50*50 and 75*75
From what I have read I believe these to be the correct sizes.
However can someone give me advice on the sizes and naming conventions for the Android side of the application.
I was told that the filenames might need to be different. Also how can it work if I want to use one icon for iOS and another for Android. Currently I specify icons like this:
var homePage = new NavigationPage(new HomePage())
{
Title = "Home",
Icon = "ionicons_2-0-1_ios-home-outline_25.png"
};
Yes, you probably want to seperate those.
You can read everything on working with different images on the documentation page. Each platform has very specific guidelines on the right image sizes, also depending on the controls you use them on. Just Google for 'icon sizes' or 'human interface guidelines' in conjunction with Android or iOS. Also, you might want to look into the MFractor plugin, which has a (paid) function to generate the right sizes for you which really saves you time.
For Android you might want to avoid using hyphens, since they are known to cause trouble.
To distinquish platforms, you can use constructions like this, for XAML:
<ContentPage>
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="Android, UWP">0</On>
<On Platform="iOS">0,20,0,0</On>
</OnPlatform>
</ContentPage.Padding>
</ContentPage>
And in code:
switch(Device.RuntimePlatform)
{
case Device.iOS:
this.Padding = new Thickness(0,20,0,0);
break;
case Device.Android:
case Device.UWP:
case Device.macOS:
default:
// This is just an example. You wouldn't actually need to do this, since Padding is already 0 by default.
this.Padding = new Thickness(0);
break;
}
(Code samples from xamarinhelp.com)
While this shows it for Padding you can apply it on strings and apply it to your situation. However, you do not have to use different filenames. You can name them identically but just use different icons. Also the platform will figure out which resolution to get or postfix it with #2x, etc.

BitmapFont in Skin doesn't draw labels correctly

I made a bitmap font using Hiero, called default.fnt and default.png. I can use these as a BitmapFont in LibGDX, and draw text with the font without problems, using font.draw(). But I can't use this font as the default font in a Skin. I've used the uiskin.json file from here(along with the rest of the skin, but I deleted the Droid Sans files before making my own font), because I have no idea how to make one of my own. From what I've read on the Internet, the .json file is correctly set up: it has the line com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: default.fnt } }, which should make the default.fnt the default font for widgets that use the skin. Still, when I run the program, I see this:
There should be a label above the buttons, and the buttons should have text.
If I do this: startGameButton.getStyle().font = font;, where startGameButton is one of the buttons, and font is the BitmapFont created like this: font = new BitmapFont(Gdx.files.internal("uiskin/default.fnt"), Gdx.files.internal("uiskin/default.png"), false);, the buttons shows the text properly. I don't want to do this since it feels too much like a hack.
I'm following this tutorial, but I've had to look some things up in later revisions of his code, because LibGDX has changed since it was written.
MenuScreen.java(the screen where there are problems)
AbstractScreen.java
Also please tell me if there's a better way to make the menu UI, or if you need other files. The uiskin.json is linked above.
Thank you.
I fixed it. The Droid Sans bitmap image existed in two places, it was part of uiskin.png too. I don't know how, but it probably read the font's letters from that file instead of default.png. So in the end I just renamed the font's .fnt and .png(and the file parameter in the .fnt) and did a search-replace inside the skin's .json, and it all works fine now. I don't know exactly what caused it, but maybe default-font is a reserved word or something.
Anyway, it works now. Thanks to Jyro117 for making me think maybe I shouldn't replace the default but add my own font.

Why do my Windows Forms strings look so ugly when anti-aliased?

I'm rendering some strings manually on top of a GraphicsBox, because you can't have a Label with a treansparent backdrop.
No matter which rendering mode I try though, I can't get the strings to look any good (ie. as they would appear in Word or in a graphics program.
Here's a picture of the interface mockup compared to what renders onscreen:
Unfortunately StackOverflow seems to shrink the picture so here's a direct link too: http://i.stack.imgur.com/vYFaF.png
And here's the code used to render:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics labelDrawing = e.Graphics;
labelDrawing.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
labelDrawing.DrawString("Setup Progress", new Font("Calibri", 10, FontStyle.Bold, GraphicsUnit.Point, 0), new SolidBrush(Color.Black), new Point(12, 9));
labelDrawing.DrawString("The following components are being configured.", new Font("Calibri", 10, FontStyle.Regular, GraphicsUnit.Point, 0), new SolidBrush(Color.Black), new Point(24, 27));
}
I've tried changing the TextRenderingHint to every option in turn, but no matter what I try if there's any antialiasing then it comes out in a blurry, smeared mess like in the screenshot. Any idea?
You can have transparent labels in .NET.
Check out this article on CodeProject on How to Use Transparent Images and Labels in Windows Forms
As for you drawing problem Calibri doesn't have a native font size of 10. You can verify this in Control Panel->Fonts. The smallest native font size is 12 (on my machine at least). Change you from size to 12 and you will see it's much better.
When you don't use native font sizes somewhere under the hood Windows/.NET/GDI+ will attempt to scale the font for you. This scaling is most likely causing your problem.

Change color of specific text only in text box of BlackBerry

How to change color of specific text only in textbox for Blackberry applications?
Unfortunately the answer is roll your own - there's no editable text field control that lets you change the font color at all. #Mark Novakowski's answer is a standard way of working around that, but will change all the text to one color.
If you're not worried about supporting the Pearl-style SureType keyboard, then you can override keyChar on ActiveRichTextField and manually add characters to the text in ActiveRichTextField.
For SureType fields, the answer is even worse - you don't have low level access to the SureType APIs (for correctly dealing with the predictive text popup) for non-qwerty phones (the Pearl series) so you have to resort to some real trickery to get a fully custom text field to function correctly on those devices. It may come down to having to have multiple EditFields arranged in a manager, with e.g. one EditField overridden to show read (as in Marks' answer). The trick there will be dynamically creating and adding text fields as necessary.
Yes, sometimes the RIM API makes easy things easy, and hard things nearly impossible.
As Fostah said in his comment, the TextBox class isn't very flexible in terms of changing the look and feel. Even the look and feel of many of the "Field" classes are pretty hard to change, too.
However, if you have some flexibility and can use a Field such as EditField (or variant thereof) instead of TextBox, then it should be just case of overriding the paint method. Something like:
protected void paint(Graphics graphics) {
graphics.setColor(Color.RED);
super.paint(graphics);
}
Have you checked out ActiveRichTextField? I've only used RichTextField myself but it looks like ActiveRichTextField lets you specify colors for the text regions in addition to fonts & formatting. It takes a little bit of set up to get these fields going but check out the javadoc for RichTextField, it gives a pretty good explanation.
Here's some sample code:
int offsets[] = new int[]{0, 5, 11};
Font[] fonts = new Font[]{Font.getDefault(), Font.getDefault()};
int bg[] = new int[]{Color.WHITE, Color.WHITE};
int fg[] = new int[]{Color.BLACK, Color.GREEN};
byte attributes[] = new byte[]{0, 1};
add(new ActiveRichTextField("Hello world", offsets, attributes, fonts, fg, bg, 0));

Resources