Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Java Font Mapping

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Font Mapping

    Java offers a way to map fonts to a logical representation, for this a fontconfig.properites file is used during JVM startup. Is it possible to load an alternate fontconfig.properties during Runtime or to change the mapping without using too much lines of code?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java Font Mapping

    Please don't double post the same question to the forums. Your other post has been removed.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Java Font Mapping

    Take a look at this - Font Configuration Files
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Junior Member
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Font Mapping

    Well that's not exactly what i'm looking for. There are several documented ways which explain the installation of fonts or change the logical font mapping depending on the operating system. If you have a look at the FontConfiguration Source Code you will find some more undocumented options e.g. force use of a specific fontconfig.properties file, but all those mechanisms are configured before runtime. Of course there is a coding style way to create and install fonts during runtime but i'm interested on changing the global fonts mapping via loading a specific fontconfig.properties file during runtime. Since the runtime system has to process the fontconfig.properties file itself there must be some kind of undocumented mechanism to handle this problem.

  5. #5
    Junior Member
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Font Mapping

    I reviewed the sun.awt.FontConfiguration and sun.java2d.GraphicsEnvironment and found a lot of methods that could be usefull, especially the ones in the FontConfiguration class. There is no way to cast to the appropriate implementation type so i did some reflection code to get access to the implemented methods:

    try {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Method getFontConf = env.getClass().getMethod("getFontConfiguration");

    Object fontConfig = getFontConf.invoke(env);
    Method loadProperties = fontConfig.getClass().getMethod("loadProperties", InputStream.class);

    loadProperties.invoke(fontConfig, fontConfig.getClass().getResourceAsStream("/fontconfig.properties"));

    } catch (Exception e) {
    e.printStackTrace();
    }

    There is no usefull documentation in the source only coding comments and just a simple loadProperties method call doesn't cover the trick at all. There must be a sequence of method calls that can be used to initizalize the fonts specified in the mapping.

Similar Threads

  1. How to Change JTextArea font, font size and color
    By Flash in forum Java Swing Tutorials
    Replies: 7
    Last Post: January 14th, 2012, 10:47 PM
  2. Java: Links, images, font and divisions with HTML / CSS
    By Cyloc in forum AWT / Java Swing
    Replies: 3
    Last Post: August 2nd, 2011, 12:54 PM
  3. hashmap & arraylist mapping
    By abhi178 in forum Collections and Generics
    Replies: 3
    Last Post: November 29th, 2010, 07:32 AM
  4. Eclipse web.xml servlet mapping???
    By nikos in forum Java IDEs
    Replies: 2
    Last Post: October 24th, 2010, 05:30 AM