Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 368375

Summary: Font size is very small in the Web Page Editor for some GTK/Linux environments
Product: [WebTools] Java Server Faces Reporter: Eric Norman <Eric.Norman>
Component: UIAssignee: Ian Trimble <ian.trimble>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: raghunathan.srinivasan, thatnitind
Version: unspecifiedFlags: raghunathan.srinivasan: iplog+
Target Milestone: 3.5 M7   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Screenshot that shows the font size in the design tab
none
Screenshot that shows the font size in the preview tab none

Description Eric Norman CLA 2012-01-11 12:41:32 EST
Build Identifier: 

Font scaling calculation is incorrect in the Web Page Editor for some GTK/Linux environments

Running these OS commands from the terminal window shows what the environment is reporting as the DPI for the display and the DPI for the fonts. 

xdpyinfo | grep dimension
  dimensions:    1920x1080 pixels (212x159 millimeters)

xdpyinfo | grep resolution
  resolution:    230x173 dots per inch

xrdb -query |grep dpi
  Xft.dpi:	96



..Now, the CSSFontManager class from the jst.pagedesigner plugin is calculating the FONT_SCALE like this:

	// the scale to convert the px to pt.
	private final static double FONT_SCALE = ((double) Display.getCurrent()
			.getDPI().x) / 72;


Unfortunately, the value returned by the Display.getCurrent().getDPI().x call appears to be the DPI for the screen (230), not the DPI for the font (96).  This results in the fonts being scaled down way too much, less than half of the expected size in this case and text becomes unreadable.

The font size looks correct if I manually change the DPI to 96 in the debugger.

Is there some way to get the font DPI from SWT to calculate the right scaling factor?  Or can we have a system property that can be manually set to force a specific value for the font DPI in this calculation?


Reproducible: Always

Steps to Reproduce:
1.In an ubuntu 10 environment, create a project and add an html file.
2.Open the html file in the 'Web Page Editor' editor
3.Add some text to the body of the html file
4.See that the font size in the design panel is really small
5.Switch to the 'Preview' tab of the editor and see the font with a more reasonable font size.
Comment 1 Eric Norman CLA 2012-01-11 12:43:09 EST
Created attachment 209327 [details]
Screenshot that shows the font size in the design tab
Comment 2 Eric Norman CLA 2012-01-11 12:43:28 EST
Created attachment 209328 [details]
Screenshot that shows the font size in the preview tab
Comment 3 Eric Norman CLA 2012-01-11 13:37:22 EST
The following code change to CSSFontManager seems to work for me, but maybe there is a better way to do it:


	// the scale to convert the px to pt.
	private final static double FONT_SCALE = fontDpi() / 72;

	//get the font DPI from the display or a system property
	static double fontDpi() {
		double fontDpi = -1;
		
		if ("gtk".equals(SWT.getPlatform())) {
			//check if AWT has a value for the gnome font DPI
			Object value = Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/DPI");
			if (value instanceof Integer) {
				fontDpi = (double)(((Integer)value).intValue() / 1024);
				if (fontDpi == -1) {
					fontDpi = 96;
				}
				if (fontDpi < 50) {
					fontDpi = 50; 
				}
			}
		}
		
		if (fontDpi == -1) {
			//fallback to the DPI reported by the display
			fontDpi = (double)Display.getCurrent().getDPI().x;			
		}
		return fontDpi;
	}
Comment 4 Raghunathan Srinivasan CLA 2012-01-11 14:08:13 EST
We will review. Thanks for providing a possible fix.
Comment 5 Eric Norman CLA 2013-04-08 12:24:44 EDT
Is there any chance of getting a fix for this issue?  The WTP html editor is not usable in the current state.
Comment 6 Raghunathan Srinivasan CLA 2013-04-08 12:33:50 EDT
We will review for M7.
Comment 7 Ian Trimble CLA 2013-04-22 19:19:20 EDT
Relevant discussion:
https://www.java.net//node/672090