United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6551615 : Need public API for creating composite fonts

Details
Type:
Enhancement
Submit Date:
2007-04-30
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2007-04-30
Component:
client-libs
OS:
linux
Sub-Component:
2d
CPU:
x86
Priority:
P5
Resolution:
Duplicate
Affected Versions:
7
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b11)
Java HotSpot(TM) Server VM (build 1.7.0-ea-b11, mixed mode)

EXTRA RELEVANT SYSTEM CONFIGURATION :
Linux helium 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
On Solaris, if i want a composite font with "Lucida Sans Typewriter", i can just choose "Monospaced". on Windows, i'm screwed.

if i want a composite *proportional* font, i can use StyleContext.getDefaultStyleContext().getFont() instead of "new Font", but sun.font.FontManager hard-codes "Dialog" as the source of the other slots' fonts.

a step forward would be to factor sun.font.FontManager.getCompositeFontUIResource so there's a version where "dialog" is passed as a parameter, so the truly desperate could at least use reflection to create their own CompositeFont.

but something like Font.setFallbackLogicalFont(String), so i could say something like:

 Font f = new Font("Lucida Sans Typewriter", Font.PLAIN, 10);
 f.setFallbackLogicalFont("Monospaced");

and have f be like Solaris' "Monospaced" everywhere, even Windows, would be sweet.


REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
i haven't found a workaround, and not for want of trying. FontManager.replaceFont and CompositeFont.replaceComponentFont seem to lead to pain and misery. FontManager.getCompositeFontUIResource, as i say, is only usable if i'm dealing with a proportional physical font.

Alternatively, you could use Mac OS. i'm not sure what layer does it, but there all physical fonts seem to get appropriate fallbacks. that rocks. if you could tell the difference between monospaced and proportional fonts (i raised a bug requesting such a Java API years ago), you could automatically add fallbacks to any physical font.

                                    

Comments
EVALUATION

> f.setFallbackLogicalFont("Monospaced");
>and have f be like Solaris' "Monospaced" everywhere, even Windows, would be sweet.

The need for this kind of functionality is already filed as
6407157 : RFE: Means to specify a Font with fallbacks for additional code point coverage

Its evaluation has a substantial discussion of the alternatives.

>if you could tell the difference between monospaced and proportional fonts
>(i raised a bug requesting such a Java API years ago),

I can't locate any such request. Its not hard to test for whether a Latin font
is monospaced by requesting the advance of "i" and "W" and if they are the
same its monospaced. 
But there are wrinkles :
1. a CJK font may be 'monospaced' but have half and full width latin chars
and there's considerable debate about what the true answer is there

2. If a font is a composite or has fall backs, is it only monospaced
if all the component fonts are monospaced?
If the latter the answer will be "false" for almost all cases.

Also I can imagine other questions about the properties of a font, such
as querying its width or weight. Perhaps a more general API that can
answer these questions would be better. But again, composites are
tricky. Giving the answer based solely on the primary font would seem
to simplify matters but some questions like is it truly monospaced
could lead to problems.
                                     
2007-04-30



Hardware and Software, Engineered to Work Together