SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-20-2007, 02:25 AM
BobPhoenix BobPhoenix is offline
SageTVaholic
 
Join Date: Oct 2004
Posts: 3,152
What is the best way to get the width in pixels of a string?

How would I go about determining the size in pixels of a string with Java calls? I'm not familiar enough with Java and the way I was trying to get it (with java.awt.FontMetrics) doesn't work. I'm assuming that is because it is an abstract class. So how else could I do this from within Studio.

Thank you for any suggestions.
BobP.

P.S. I'm trying to implement a scrollable text input. I've got it working with a character count of the string but would like to get down to the pixel level if it is possible.
Reply With Quote
  #2  
Old 01-20-2007, 02:20 PM
gplasky's Avatar
gplasky gplasky is offline
SageTVaholic
 
Join Date: Jul 2003
Location: Howell, MI
Posts: 9,203
I don't know but I think it was nielm who actually posted an STV that had examples of acual scroll bars in Sage TV. This had scrolling panels, scrolling tables, multi column and wrapping. Might this help you?
Scrollbars

Gerry
__________________
Big Gerr
_______
Server - WHS 2011: Sage 7.1.9 - 1 x HD Prime and 2 x HDHomeRun - Intel Atom D525 1.6 GHz, Acer Easystore, RAM 4 GB, 4 x 2TB hotswap drives, 1 x 2TB USB ext Clients: 2 x PC Clients, 1 x HD300, 2 x HD-200, 1 x HD-100 DEV Client: Win 7 Ultimate 64 bit - AMD 64 x2 6000+, Gigabyte GA-MA790GP-DS4H MB, RAM 4GB, HD OS:500GB, DATA:1 x 500GB, Pace RGN STB.

Last edited by gplasky; 01-20-2007 at 02:27 PM.
Reply With Quote
  #3  
Old 01-20-2007, 02:29 PM
BobPhoenix BobPhoenix is offline
SageTVaholic
 
Join Date: Oct 2004
Posts: 3,152
Quote:
Originally Posted by gplasky
I don't know but I think it was nielm who actually posted an STV that had examples of acual scroll bars in Sage TV. This had scrolling panels, scrolling tables, multi column and wrapping. Might this help you?
Scrollbars

Gerry
I take a look. It might. Thanks.
Reply With Quote
  #4  
Old 01-22-2007, 09:22 PM
BobPhoenix BobPhoenix is offline
SageTVaholic
 
Join Date: Oct 2004
Posts: 3,152
OK I figured a way to make my idea work with one exception. It appears that at 640x480 the font size is ruffly the same as the equivalent in WordPad. But it is obvious that the font is enlarged when going to full screen or reduced when going to 320x240. So my question is what is the ratio used? Because the letters at 320x240 are not 1/2 half size and the letters at 1280x960 are not 2x the size.

Thoughts?

BobP.
Reply With Quote
  #5  
Old 12-16-2007, 02:56 AM
BobPhoenix BobPhoenix is offline
SageTVaholic
 
Join Date: Oct 2004
Posts: 3,152
I thought I would post the solution I found for this in case anybody was interested:
Code:
    public static int getTextWidth(String text, String fontName, 
            String fontStyle, int fontSize, int screenWidth) {
        float size = (screenWidth / 640.0F) * fontSize;
        java.awt.Font font = java.awt.Font.decode(fontName + "-" + fontStyle + "-" + fontSize);
        font = font.deriveFont(size);
        java.awt.Label label = new java.awt.Label(text);
        java.awt.FontMetrics fm = label.getFontMetrics(font);
        int width = fm.stringWidth(text);
        return width;
    }
Where:
  1. Text is the string you want the size for.
  2. Font??? are the font attributes from a theme.
  3. ScreenWidth is the value returned from GetFullUIWidth api call.
  4. The label can also be a pre-existing label and does not have to contain the text you want the size for I just used it that was as a convenience.
The next hardest part is figuring out the size of the TextInput Widget but it is just a combination of GetFullUIWidth() and all the sizes of panels and insets in between the UIWidth and the TextInput widget. It would be nice if another API was added that would allow you to pass a widget preferably or the widget name and return the size on screen in pixels!

BobP.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 01:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.