Applet loading and using ttf font

Hello,
I'd like my applet to load a TTF file from the server (or from a provided jar file) and
use it to render text, or use it with GUI elements like TextArea.
Here the significant part of my code:
        URL fontURL=applet2.class.getClassLoader().getResource("my.ttf");
        try { fontStream = fontURL.openStream(); } catch (Exception e) {
            str=str+"Error 1\n";
            e.printStackTrace();
        str=str+"Step 1\n";
// also tried this way instead, as well as including the ttf in a jar or as separate file on the server
//      fontStream = getClass().getResourceAsStream("my.ttf");
        try { font = Font.createFont(Font.TRUETYPE_FONT, fontStream); } catch (Exception e) {
            str=str+"Error 2\n";
            e.printStackTrace();
        str=str+"Step 2\n";
        try { fontStream.close();} catch (Exception e) {
            str=str+"Error 3\n";
            e.printStackTrace();
        str=str+"Step 3\n";
        big_font=font.deriveFont(40f);
        text_out_main = new TextArea(str,4,40,TextArea.SCROLLBARS_NONE);
        text_out_main.setFont(big_font);the funny thing is, that this works on several Linux installations I tried (all UTF8/Unicode based ones).
And I tried several WinXP/Win2k FF/IE/Safari combinations and none of them works! The Windows
machines all show a standard font but with the size 40f, I cant see any exceptions, the strings "Step 1"
to "Step 3" are nicely attached to the main string and not a single "Error x" string appears.
All systems use the latest jre 1.6 plugins.
Any hints are appreciated.
Thanks,
Leander
Edited by: Leander2000 on Jun 7, 2008 5:55 AM

Meanwhile I found out that the TextArea (or probably any other awt gui element)
did not use the font when running on Windows, when drawing to a Graphic or using
it with a JTextArea everything is ok.
Regards,
Leander

Similar Messages

  • Embedding and using external fonts.

    I'm using Flash CS4.  I'm trying to load and embed an external font.  The main problem I'm having is that I need to import more than just latin 1.  I need many special characters imported as well.  Because of this, using Flash CS4's create new font from the library is not an option.  I'm using Verdana, so I know the font has all the characters I need.
    So what I need to do is create an external swf that holds the font.  Then I need to import and use the font.  Unfortunately, I've found way too many ways online that work but don't fit my needs.
    Any help is appreciated.

    1. Embedding
    a. You can embed font in Flash IDE by creating Font as a library asset and then compile this swf. There are tons of help available on Internet.
    b. If you use Flash CS5 or compilers that utilizes Flex SDK, you can create class like below and compile it into a swf:
    package 
         import flash.display.Sprite;
         public class FontLibrary extends Sprite
              [Embed(systemFont="Verdana", fontName="_verdana", mimeType="application/x-font", advancedAntiAliasing="true", fontStyle="normal",unicodeRange="U+0020-U+007E")]
              public static var Normal:Class;
              [Embed(systemFont="Verdana", fontName="_verdana", mimeType="application/x-font", advancedAntiAliasing="true", fontStyle="normal", fontWeight="bold",unicodeRange="U+0020-U+007E")]
              public static var Bold:Class;
              [Embed(systemFont="Verdana", fontName="_verdana", mimeType="application/x-font", advancedAntiAliasing="true", fontStyle="italic", fontWeight="normal",unicodeRange="U+0020-U+007E")]
              public static var Italic:Class;
              [Embed(systemFont="Verdana", fontName="_verdana", mimeType="application/x-font", advancedAntiAliasing="true", fontStyle="italic", fontWeight="bold",unicodeRange="U+0020-U+007E")]
              public static var ItalicBold:Class;
    No matter what way you choose - you will have font available the external swf.
    Try to load external swf into current domain. When you load the swf there is no much to do. Once swf is loaded - fonts should be available throughout application.
    To use the font - just pass its name into TextFiled instance's TextFormat. WIth the example above:
    myTextFormat.font = "_verdana";
    Documentation for TextFormat:
    http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextFormat.html
    To see available fonts you can use the following:
    var allFonts:Array = Font.enumerateFonts(false);
    allFonts.sortOn("fontName", Array.CASEINSENSITIVE);     
    for (var i:int = 0; i < allFonts.length; i++)
         trace(allFonts[i].fontName);

  • When you create a PostScript file you must rely on system fonts and use document fonts

    I got this error:
    "When you create a PostScript file you must rely on system fonts and use document fonts. Please go to the printer properties, "Adobe PDF Settings" page and turn OFF the option "Rely on system fonts only; do not use document fonts."
    This strikes me as bad practice. I only want to use system fonts and document fonts will muck me up.
    That being said, I could not easily find a way to fix this with Acrobat Pro XI. I opened Control Panel (Windows 8) and found the printer and mucked around in the various ways to get to change the PDF settings (there are several ways, and some of them present the choices as bold and not just regular). I found two separate switches for "Rely on system fonts only; do not use document fonts" and turned both off, BUT that did not work.
    Frustrated, I went back to FrameMaker and clicked File > Print Setup and then for the PDF printer, Printer Properties. There I found a THIRD instance of "Rely on system fonts only; do not use document fonts" that was set differently than the other two. This was the setting the error message meant. Change this one.
    Thanks for the convoluted UI, Adobe. What a pain, but there is the answer for all who follow after....

    > Windows 7 and Frame 7.2.
    This is not a supported configuration and probably does not work, due (I'm guessing) to driver API changes from XP to Win7, which would affect generating PDF and Ps output. This would affect Save-as-PDF and Print-to-Ps+Distill (unless you have a newer version of the full Acrobat product).
    As it happens, I'm going to attempt something similar: FM 7.0 on Win7 64 Pro. However, I'm going to install that old FM in "XP Mode".
    XP Mode is a 32-bit virtual machine running actual Windows XP inside Win7. It is (now maybe "was") available for Windows 7 Enterprise, Professional and Ultimate (but not Basic, Home or not-so-Premium). When XP went off support life earlier this month, Mr.Bill may have taken down the ability  to download XP Mode (or not, since some large enterprises are able to  purchase continued support for XP at some great cost). XP Mode never was supported for Win8. There are other VMs for Windows available.
    If XP Mode is still available, you also need a CPU that has hardware virtualization, which all recent 64-bit AMD processors do, but which is fused-off in many low end 64-bit Intel processors. AMD processors need a separate unobvious hot-fix patch installed before you do anything else about XP Mode.

  • How do I setup and use Hawaiian fonts?

    How do I setup and use Hawaiian fonts in OSX 10.7.4?  The instructions I obtained by Googling no longer seem to work.  See Wahinoho.net
    Message was edited by: fbeckner

    How do I setup and use Hawaiian fonts in OSX 10.7.4?  The instructions I obtained by Googling no longer seem to work.  See Wahinoho.net
    Message was edited by: fbeckner

  • Can CS6 be loaded and used in a Citrix environment?

    Can CS6 be loaded and used in a Citrix environment?

    And that is exactly meant to mean what? You need to be a lot more specific. You know, I could play dumb and pretend I didn't even know what "Citrix" is (A toilet cleaner based on Citric acid perhaps?). You have to provide exact version numbers, system specs, configurations and what you plan to do. There are specific technical limitations on running CS products in virtual environments and it may even be a breach of the licensing terms depending on what licesne you actually have. A lot more to it than just your generic question.
    Mylenium

  • Embedding and using external fonts in Flash CS5

    I just upgraded to Flash CS5.  Font embedding is entirely different than it was in CS4.  I've been looking for examples online but none seem to show me a solution that matches what I need.
    In the project I'm working on, code changes the font a text box uses based on region and language.  To keep file size down I created separate swf files with the fonts embedded.  That way I only download the font I need.  The way I did this and the code I used in CS4 doesn't seem to work anymore.  Can someone please point me to a tutorial on this.
    Thanks

    OK, maybe you can help me figure out what I'm doing wrong.  Below is the code I'm using.
    LOADING THE FONT
    Font SWFs:
    I'm trying something new with CS5.  To create a swf with the font I need I'm creating a library symbol of the font with all the characters in it.  Titled it "Verdana".  I've also turned on Export for ActionScript and given the font a unique class name (VerdanaFont).  Then of course publish the swf, name it Verdana.swf, and put it in the correct location.  Does doing it this way automatically register the font?
    The Loader code:
    private function LoadFont()
    var fontPath:String = "assets/fonts/Verdana.swf";
    var fontLoader:Loader = new Loader();
    fontLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, createTextBox);
    fontLoader.load(new URLRequest(fontPath));
    The TextBox code:
    private function createTextBox()
    var tf:TextFormat = new TextFormat;
    tf.font = "Verdana";
    tf.align = "left";
    var textBox:TextField = new TextField;
    textBox.embedFonts = true;
    textBox.selectable = false;
    textBox.htmlText = "This is test text";
    textBox.setTextFormat(tf);
    stage.addChild(textBox);

  • How to use .ttf font in muse ?

    Hi,
    I have a question, I want to make a website using thai font (which is Angsana New  ). I have the font which in .ttf
    I have the font installed in my system and overtime I upload the website the font will exported as an image.
    Can someone help me by teach me how to make the css for that ?
    Thanks in advance

    You need to convert it to webfont
    Create Your Own @font-face Kits | Font Squirrel
    and then follow this tutorial
    Add self-hosted web fonts | Adobe Muse CC tutorials

  • Using TTF Fonts in ROME

    Hello,
    i've been using Rome for several months now (meaning since almost the first days of the prerelease) and i'm pretty satisfied. I use ROME for all my graphics i have to create for my work. I even do my presentations with ROME. But now i've stumbled over a little problem. I need to use CI-Fonts which are only available in the TTF-format.
    Is there any way to use those fonts in ROME? I've noticed that ROME seems only to be capable of using SWF Fonts. Hope someone can help me with that ;-)
    Best regards,
    Mathias

    I have a whole lot of .ttf fonts in my special fonts
    folder
    The usual place to put them would be Users/username/Library/Fonts. Is that where they are?

  • What is the best way to add and use custom fonts with Eloqua?

    We have a custom font that we'd like to use with Eloqua and were wondering how others might have successfully approached this.

    ~~Disclaimer: This answer refers to email fonts only - landing page font imports are discussed below~~
    Hi Brett,
    I took a look at these two posts: Re: Tips for getting the E10 email editor to change the email font for Outlook & other old-school email clients? and Re: E10 Fonts
    It seems that there are reasons as to why only a few of the fonts are supported. You can drill down into the source code to edit the font type, but I'm not sure that will get you anywhere.
    To drill down:
    To get the desired font & size in various clients (Gmail, Hotmail, Yahoo, Outlook) I found that specifying in the html works best.
    So whether it’s a P or TD, tag I add the style attribute & specify the font along with color & size.
    e.g.:
    <td style="LINE-HEIGHT: 18px; FONT-FAMILY: Arial, Helvetica, sans-serif; COLOR: #000000; FONT-SIZE: 12px;">
    Of course if you use the WYSIWYG editor you will have to view the html source & add this.

  • Loading library.swf (unpacked from swc) using loader() and using it's assets

    I try to load libary.swf from an swc file in order to use it's library items.
    i load the library.swf using urlrequest and loader() and then use getDefinition() to fetch the class definition
    of the UIMovieclip element.
    i simply created the swc file by adding library assets to an swf file, converting them to a flex component and extending each compoent with the UIMovieClip class.
    when i load the swf file from a url (http) i get the following error:
    VerifyError: Error #1053: Illegal override of UIMovieClip in mx.flash.UIMovieClip.
    when i load the file locally, i get no error. any ideas why?
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">
        <fx:Script>
            <![CDATA[
                import mx.core.UIComponent;
                import mx.flash.UIMovieClip;
                private var _context: LoaderContext;
                private var _request: URLRequest;
                private var _loader:Loader;
                private var _library:Object;
                private var _executeFunction:Function = null;
                public function _setExecuteFunction(f:Function):void {
                    this._executeFunction=f;
                public function handleLibInitialized(e:Event):void {
                    this._library=e.target.applicationDomain;
                    var a:Class = this._library.getDefinition("lobby_page_component");
                    var b:MovieClip = new a() as MovieClip;
                    var c:UIComponent = new UIComponent();
                    c.addChild(b);
                    this.addElement(c);
                public function init():void {
                    Security.allowDomain("*");
                    var url2:String="http://url/for/library.swf"; <- http provides an error
                     var url2:String="/path/to/library.swf"; <- local path works
                                 this._context = new LoaderContext(false,ApplicationDomain.currentDomain);
                    this._request = new URLRequest(url2);
                    this._loader = new Loader();
                    this._loader.contentLoaderInfo.addEventListener(Event.INIT,this.handleLibInitialized);
                    this._loader.load(this._request,this._context);
            ]]>
        </fx:Script>
    </s:Application>

    hello,
    thanks for trying to help.
    if this is the case, why it happens only when i load the library.swf file from an http location instead of a local location ?
    how can i make sure that my adobe flash has the same UIMovieClip version?
    kfir

  • Anti alias and Use device font not why is that not working?

    I am editing a flash template that I have and I know
    about the anti alias setting and I went through all the text boxes and set them to use device fonts and they all seem to b
    e working except for the sliding text boxes, see attached images that show the sliding box (the gray color) and the text box behind it, when I drill down to the text box it is set to use device fonts already but when I enter my text it does not show all the letters (the W A and V for example are missing) I know that is caused by the Antialias setting but I am unable to find what is set to that in this sliding box, what am I missing? I am a very novice user so please be as detailed as you can in you answer, I can provide any information needed. Thank s in advance.
    I am using CS10

    I had the same issue. They say that because TRC Sri Lanka haven't registered IPad or apple as a safe product. That means the IMEI of apple products will not match with srilankan regulatory specifications. But this issue will be solved in near future. Please contact telecommunications and regulatory bord for details. Dialog axiata can't help.

  • Question about loading and using Images.

    I know how to load an image and to draw it onto a canvas etc etc. However my question is to do with the efficiency of loading multiple images (possibly the same image!) and using them together. I have multiple objects, all instances of the same class, which all draw themselves onto a screen in different positions. However they all use the same 3 images (depending on an internal state).
    So if I create 5 of these objects and each object calls to load the same image using something along the lines of:
    url = this.getClass().getResource("MyImage.png");
    normalImage = Toolkit.getDefaultToolkit().getImage(url);Does this mean that in the memory there are 5 exactly the same copies of this image? Or does java do something clever and use one image that they would all reference? I suspect I will have 5 in memory but I wanted to ask about this before going and making an imageManager class where I load all the images and just use getMethods in that when drawing. I will not be preforming any transforms or anything on any of the images so they can all literally be the same image but simply drawn in multiple positions on the one canvas.
    (note: I am using active rendering to draw these images myself and then blit it to the screen ...).

    Use ImageIO rather than Toolkit--with Toolkit you need to use a MediaTracker to ensure you have your image loaded before you try to use it.
    If you load an image and then do this:
    MyImage1 = MyImage;
    MyImage2 = MyImage;
    MyImage3 = MyImage;
    There are 4 references to the Image in MyImage. If you don't specifically use a method that gives you a new Image, usually, you are getting a refrence to an image already loaded in memory.

  • How to down load and using OpenStreetMap offline with LabVIEW 2013

    Dear All
    How can i download the OpenStreetMap  database and API for LabVIEW to call this offline map database !
    Thanks
    Luong.Tran
    Solved!
    Go to Solution.

    Hi Hockeyjim07
    I mean how can i use OpenStreetMap with offline mode. base on your link  it is required the computer have to access internet.  so my question is how can i download the OpenStreetMap database(pictures) and setup to offline mode and using OSM api to call the offline map?
    Thanks
    Luong.Tran

  • Adobe X Standard cannot load/create EuroRoman.ttf font after file has been created using AutoCAD LT 2015. File was loaded and refereneced with Distiller X. Font has been installed to Win7

    Need suggestion on how to get Adobe X to create/load the font. Others in the office can create the same Adobe file with no issues. Help please.

    You have the required Xorg drivers and those errors appear to be expected (https://www.virtualbox.org/ticket/4789). As a matter of fact, Xorg is terminating successfully. Just to make sure, is your ~/.xinitrc setup correctly?

  • Applet load and memory leak

    what are some methods to load an applet faster that is on the local machine? also, are there any applications to test for memory leaks? and are there ways to invoke garbage collection with code? thanx in advance.

    Applet on the local machine will load faster because file is already there
    use System.gc() to do a garbage collection

Maybe you are looking for