Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Precise font metrics

Hi Stephan,


I'm not sure if it's suitable for your requirements, but I recently had a problem with metrics for strings without ascenders/descenders etc, that I needed to fit within pre-determined vertical bounds so I wrote a small method that uses a very
simplistic approach to work out the exact height  of the actual rendered text for a specific string.

It can be used to select the correct font size for the height you require in combination with the other code on this page;

http://stackoverflow.com/questions/5829703/java-getting-a-font-with-a-specific-height-in-pixels/7737840#7737840

I hope you find it useful.


Sincerely,

Rob




                                                                                                                                                                                                                     
             Stephan Aßmus <superstippi@xxxxxx>                                                                                                                                                                    
             Sent by: platform-swt-dev-bounces@xxxxxxxxxxx                                                                                                                                                           
                                                                                                                                                                                                                                                       To
                                                                                                             platform-swt-dev@xxxxxxxxxxx                                                                            
             24/10/2011 15:38                                                                                                                                                                                                                          cc
                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                  Subject
                                                Please respond to                                            [platform-swt-dev] Precise font metrics                                                                 
                "Eclipse Platform SWT component developers list."	<platform-swt-dev@xxxxxxxxxxx>                                                                                                                     
                                                                                                                                                                                                                     
                                                                                                                                                                                                                     
                                                                                                                                                                                                                     
                                                                                                                                                                                                                     
                                                                                                                                                                                                                     




Hi all,

The FontMetrics class only returns rounded int values for ascent,
descent and leading values, but I need to know the precise floating
point measurements.

I've searched the web for a solution to this problem, but even though I
think people would stumble over this issue more frequently, I have found
nothing helpful.

Basically, my situation is this. I am working on an SWT/JFace
application where the user can edit large rich text documents (WYSIWYG
in pages). To support this we developed a new styled text document model
with a LineStyleListener based adapter to the SWT StyledText control.
The StyledText control itself and the LineStyleListener interface needed
heavy modifications for all the features that we needed. In principle we
would be willing to donate the related code. At least when I initially
researched rich text editing, it appeared many developers were also in
need for a powerful framework similar to what is available in Swing. One
problem with me donating code could be that I can't promise to maintain
anything. But if there were plans already to offer a rich text framework
in JFace/SWT that is not focussed on editing code so much as is current
JFace/Text, it may be a good starting point.

Anyway, after not paying it enough attention for the longest time, I was
looking into more precise text rendering and comparing the amount of
glyphs per line and number of lines per page with other text packages
and I am realizing that the rounding of the font metrics to integer
values could be posing quite a problem for my use case. Neither can I
control text rendering beyond anti-alisaing on/off, nor can I position
each line based on individual absolute rounding from the page top. So
the font metric rounding adds up and I end up fitting much less text on
a page compared to other professional text packages.

Can anyone provide some directions which I could investigate to solve
this problem? Thank you for any help!

Best regards,
-Stephan

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev



------------------------------------------------------------------------------------------------------------
Get the best from British Airways at ba.com
http://www.ba.com

--
This message is private and confidential and may also be legally privileged.  If you have received this message in error, please email it back to the sender and immediately permanently delete it from your computer system.  Please do not read, print, re-transmit, store or act in reliance on it or any attachments.

British Airways may monitor email traffic data and also the content of emails, where permitted by law, for the purposes of security and staff training and in order to prevent or detect unauthorised use of the British Airways email system.

Virus checking of emails (including attachments) is the responsibility of the recipient.

British Airways Plc is a public limited company registered in England and Wales.  Registered number: 1777777.  Registered office: Waterside, PO Box 365, Harmondsworth, West Drayton, Middlesex, England, UB7 0GB.

Additional terms and conditions are available on our website: www.ba.com



Back to the top