Flex embedding 'condensed' typeface of a font - flex3

I am trying to embed different typefaces of a font and have a .otf for each of them. It looks like Flex only supports 'bold','italic'. But what do I do if I want to embed 'bold-condensed', 'regular-condensed' and 'black'. How would I achieve that?

If someone else stumbles over this:
You need to import the font using open-type or true-type (.otf or .ttf) and give name it differently
[Embed(source='assets/fonts/Interstate-BoldCondensed.otf',
fontName='interstateBoldCondensed',
mimeType='application/x-font',
advancedAntiAliasing='true'
)]
private var font1:Class;
[Embed(source='assets/fonts/Interstate-Light.otf',
fontName='interstateLight',
mimeType='application/x-font',
advancedAntiAliasing='true'
)]
private var font2:Class;
[Embed(source='assets/fonts/Interstate-RegularCondensed.otf',
fontName='interstateRegularCondensed',
mimeType='application/x-font',
advancedAntiAliasing='true'
)]
private var font3:Class;
then you'll just treat them as if they were different fonts and reference them by their 'new' name: e.g. 'interstateRegularCondensed'.

Related

Display UTF-8 JSPdf with VueJS

I am trying to display a catalog of products in pdf using JSPdf with VueJS. Data are coming from an API.
Base on the choice langage, the data will be in English, French etc...
Letters are working in English. But in French the problem is for letter like "é è à ç" etc... All this letter are displaying in a strange way. I read a lot of about setting a new font but it's still not working like this.
So I am coming here to see if somebody can share a script using VueJS to setup a custom fonts working with UTF-8 enconding.
Here is a minimal function but the idea is here:
download() {
let pdfRef = this.$refs.pdf;
html2canvas(pdfRef).then(canvas => {
let pdf = new jsPDF();
const str = "éçàeéi test";
pdf.save("Articles.pdf");
});
},
On the pdf i will see. Sometimes some letters are blank also.
é è à ç test
instead of
éçàeéi test
Thank you in advance.
Have a nice day!
Following this Link it's working perfectly. It's funny i following this doc before but i did not use a binary string to convert my ttf font.
I downloaded the font on google fonts and after i used a website to convert file ttf to base64 and get the string for the variable const myFont. Don't be scared because it can be thousand of letters
Just after the solution!
Thank you for your help and have a nice day :)
const myFont = ... // load the *.ttf font file as binary string
// add the font to jsPDF
doc.addFileToVFS("MyFont.ttf", myFont);
doc.addFont("MyFont.ttf", "MyFont", "normal");
doc.setFont("MyFont"); ```

Prevent system FontSize change from affecting the size in the Xamarin Application

So I noticed that an App I made will look messed up if the Font size in the users phone is changed to above medium, I googled a bit found many unanswered or answered but not to the point of the same question.
I want to be able to do that in the PCL class if possible , if not possible then the most interesting platform for me is android so a fix specific for android would do.
Here is a sample of my Xaml code so you can get a reference:
<Label Text="STORE" FontSize="23" HeightRequest="40" WidthRequest="212" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"></Label>
So to be clear the question is how do I prevent the system from overriding my fontsize which is 23 in this case?
Thanks
SImply add this in your MainActivity after OnCreate.
#region Font size change Prevent
public override Resources Resources
{
get
{
var config = new Configuration();
config.SetToDefaults();
return CreateConfigurationContext(config).Resources;
}
}
#endregion Font size change Prevent
For those who still struggle how to disable accessibility font scaling on Android.
You need to create custom renderer for label, button and common input controls like this:
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Label), typeof(MyApp.Droid.Renderers.LabelRendererDroid))]
namespace MyApp.Droid.Renderers
{
class LabelRendererDroid : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (e.NewElement == null) return;
Control.SetTextSize(Android.Util.ComplexUnitType.Dip, (float)e.NewElement.FontSize);
}
}
}
For Xamarin picker controls there is no FontSize property, so we can add it to App class:
public static double NormalFontSize => Device.GetNamedSize(NamedSize.Medium, typeof(Picker));
and then utilize it in picker renderer:
Control.SetTextSize(Android.Util.ComplexUnitType.Dip, (float)App.NormalFontSize);
Also by changing this NormalFontSize property we can set whatever desired font size for picker, as it is not available without renderer.
Have you seen the items in chapter 5 of this book?
https://developer.xamarin.com/guides/xamarin-forms/creating-mobile-apps-xamarin-forms/
Although not an exact answer, depending on what you are attempting to do you might be able to use the example at the end of the chapter modified to allow for a "Max" font size. All from within the PCL.
It's worth noting however that the inability to scale the font to a big size could be an indication of accessibility problem.

RichEditBox : set a style only for the characters that are about to be written

I'm trying to create a simple text editor in a Windows 8 application, like a simple OneNote. I can set font size, font color and font style, but the problem is that it's applied to the whole content of my RichEditBox, even to the text that has already been written. But I would like that, when I select "Italic" for exemple, only the future characters should be written in Italic, and the words and characters already written remain in the style they were.
It's quite difficult to describe.
Do I use the good XAML element (RichEditBox) ? Is there a method to select the actual position of the writer in the RichEditBox ?
Thanks for your answers !
Try this button event. rebTextNote is RichEditBox object.
using Windows.UI.Text;
public void btnItalic_Click(object sender, RoutedEventArgs e)
{
ITextCharacterFormat format = rebTextNote.Document.Selection.CharacterFormat;
if (format.Italic != FormatEffect.On)
format.Italic = FormatEffect.On;
else
format.Italic = FormatEffect.Off;
}

Flex: Embedding fonts at runtime only works locally?

I'm trying to change the text format in a TextField I get from a .swf. I'm embedding my font in a myFont.swf:
public class TemplateFont extends Sprite
{
[Embed(source='../fontFiles/geogrotesque/Geogrotesque-Regular.ttf', fontName='theFontName')]
public static var FONT_TEXT:Class;
}
Then I'm loading it where I need it and registering it:
var FontLibrary:Class = e.target.applicationDomain.getDefinition("TemplateFont") as Class;
Font.registerFont(FontLibrary.FONT_TEXT);
And then I'm trying to set the format to my Textfield:
txtTitle.embedFonts = true;
txtTitle.antiAliasType = AntiAliasType.ADVANCED;
var titleFormat:TextFormat = txtTitle.getTextFormat(); //TextFormat is set in swf, just wanna change font at runtime.
titleFormat.font = "theFontName;
txtTitle.htmlText = title; //coming from xml sorrunded with CDATA
txtTitle.defaultTextFormat = titleFormat;
txtTitle.setTextFormat(titleFormat);
This all works fine when I'm running it on my computer, but as soon as I place my files on a server nothing shows. When I'm tracing the htmlText for the TextField it looks fine, but no text is showing up. I'm also tracing the registered fonts to see that they are there, and they are.
Anybody knows?
Two things:
The EULA of this font don't allowed to upload the font to a server.
Have you a legal copy of Geogrotesque? We only sell Open Type format (OT), but not True Type (TTF).
If you have doubts about this, please contact with Emtype.

How to Get Font Properties from a Font File Name?

I'm trying to use Linq to loop through all fonts in the %windir%\Fonts folder and find the one that has a property title of "Arial" (or any Font Family name supplied), but I can't seem to access the font properties (things like "Title", "Font style", "Designed for", etc.).
The following is only giving me the basic file info:
Dim fontDir = Environment.GetEnvironmentVariable("windir") & "\Fonts\"
Dim fontFiles = From file In My.Computer.FileSystem.GetFiles(fontDir)
Dim fontInfo = From fontFile In fontFiles Select _
My.Computer.FileSystem.GetFileInfo(fontFile)
What I'd love to put on the end is something like ...Where fontFile.Title = "Arial". Any advice here?
The reason I need to do this is to find the one with one or more properties, like Title, and then physically copy that font file to another directory.
Instead of doing that you can use the framwework System.Drawing.Text.InstalledFontCollection class and ask for the installed font. Get the list and use linq to execute that.
Alternatively, doing it with your way above you will have to load the font into System.Drawing.Text.PrivateFontCollection then applied query just like above to find the font.
Edited to add this so other can spot it easily:
To find the file association, I had to do it by enumerating one or both of these registry key to find the font name and their corresponding font file. The font folder is always located in "%Windows%\Fonts"
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts
You should probably be using the System.Drawing.Text.InstalledFontCollection class instead of probing the filesystem directly. You could then do something like so:
var arialFontFamilies = from fontFamily in new InstalledFontCollection().Families
where fontFamily.Name.Contains("Arial");
If you wanted to access more properties, you could create Font objects:
var arialFonts = from fontFamily in new InstalledFontCollection().Families
where fontFamily.Name.Contains("Arial")
select new Font(fontFamily, FontSize.Regular);
If you still need to access a custom set of fonts from anywhere on disk, you could use the PrivateFontCollection class:
var fontFiles = from fileInfo in (from file in My.Computer.FileSystem.GetFiles(fontDir) select Computer.FileSystem.GetFileInfo(file));
var privateFonts = new PrivateFontCollection();
foreach (var fontFile in fontFiles)
{
privateFonts.AddFontFile(fontFile.FullName);
}
var arialFonts = from fontFamily in new privateFonts.Families
where fontFamily.Name.Contains("Arial")
select new Font(fontFamily, FontSize.Regular);