Font size of Java?

Hi, I have a question about the font size.

First when you create a new font is pt or px size (I think it's pt)

Then, a web browser has a 16px default font size how do you create a Java font is this size?
And, how do you scale?

font.deriveFont (32.0) - is it 32pt or 32px (is this 200% of 16px) how to make 200% of 16px?

Any thoughts would be appreciated.

Richard

I came up with a way to get from 16px in pt for a particular screen by the following. I was wondering if there is an easier way?
import javax.swing.*;
import java.awt.*;
import java.awt.font.*;

public class Main
{
    public static void main(String[] args)
    {
        Frame frame = new Frame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

class Frame extends JFrame
{
    public Frame()
    {
        setTitle("Get font px to pt");
        setSize(300,300);
        JPanel panel = new Panel();
        add(panel, BorderLayout.CENTER);
    }
}

class Panel extends JPanel
{
    public void paint(Graphics g)
    {
        Graphics2D g2 = (Graphics2D)g;
        super.paint(g);
        FontRenderContext context = g2.getFontRenderContext();
        Font font = new Font("Times New Roman", Font.PLAIN,1);
        String test = "A";
        boolean found = false;
        float i = 1.0f;
        while(i < 20.0f && !found)
        {
            Font f = font.deriveFont(i);
            LineMetrics lm = f.getLineMetrics(test, context);
            float h = lm.getHeight();
            if(h >= 16)
            {
                found = true;
                g2.drawString("Standard 16px is "+i+"pt", 10, (int)(h+10));
            }
            i += 0.1f;
        }
    }
}
Published by: 827028 on March 25, 2011 20:27

A way to generate a font that produces a specific pixel for a certain string height must create a TextLayout to the string object using the base font, use getBounds () .getHeight () on it to find out the height, and then derive a font of this base font which is reduced by a transformation affine height pixels You must use the baseFont.deriveFont (at) corresponding to your affine transformation (that you define to a scaling by the required report). Generate the TextLayout will require a FontRenderContext, that contains the information needed to translate the point size of the font to a height of pixel for the display device.

Tags: Java

Similar Questions

  • change /-the font size of a text field on master pages is not possible? (field prop)

    Hello

    I would like to change the font and the font size of a textfield on a master page.

    I wonder if I did anything wrong, because font options (size, fonts, etc.) are simple grayed out / not available, when I click on my text field.

    Apparently, there is a way to customize the font properties of a textfield (only) on the master page.

    Well, I guess it would work with java script in the event init... but really, why the hell it should not possible just use properties/text properties?

    Please correct me if I'm wrong. I'm doing something wrong, or is it really not possible to customize the police of a text field on master pages?

    Import you the form in the designer?

  • Font size too small in 10 IOS on iPhone email

    Hi after downloading 10 IOS on my iPhone font size in the body of the emails became very small. I have to zoom to read while before it adjusts the size automatically to the size of normal as police elsewhere. How can they be corrected? Thank you

    You can disable thread for this problem. Settings > mail > organize by thread (off).

  • IOS10 FONT size of email problems

    Resizing fonts in email threads has always been consistent with IOS9. Not with IOS10. In fact, the police is smaller and makes it difficult to read if you are visually impaired. This is not an improvement, and I was very happy with IOS9. Why fix something that isn't broken?

    Hello and welcome to Apple support communities, BryanCBT.

    If I understand your message to the right, the font size of the e-mail messages in your mail app is too small, and you have trouble reading. I am happy to help you with a solution for this then you can start to take advantage of Mail in iOS 10.

    You can actually very easily change the font on your iPhone in settings > brightness and view > text size. If you need even larger font sizes, you can do it in the accessibility settings. Here are the steps:

    Larger font

    1. Go to settings > general > accessibility > bigger text (or more big Type of iOS 7).
    2. Turn on the accessibility of size (or more big dynamic Type in iOS 7) for larger font options.
    3. Drag the cursor to select the desired font size.

    Turn on the other accessibility settings

    Go to settings > general > accessibility to make the "BOLD" text, increase the contrast or invert the colors on your screen.

    Change the font size on your iPhone, iPad and iPod touch

    There are also a few additional accessibility features available for the needs of the vision. You can view all here:iOS. A wide range of features for a wide range of needs.

    Thank you for using communities of Apple Support.

    Take care.

  • Is it possible to increase the font size on web pages? I can increase the size of the page but then lose the ability to see the entire page.

    I've just updated El Capitan, but the font size on web pages went all teeny weeny.

    I was wondering if we could increase the font size? The page can expand via "zoom in", but then lose the ability to view the web page in the blink of an eye.

    Thanks in advance.

    Yes.  Open the Terminal app and type the following command followed by the Enter key or return:

    : write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2MinimumFontSize - int XX

    (triple click on the line to select it to copy and paste into the Terminal application).

    Change the XX to the font size you want as the minimum font by default.

    Or you can use a css style sheet.  This site describes it and the Terminal method: specify Minimum font size in Safari 10.0, macOS Sierra

  • Incompatible font size.

    Hey guys,.

    I'm 10.0.2 on an iPhone IOS 7 more. The strangest thing happens... when I go to Contacts > (person in contacts) > change > list of incompatible randomly watch sizing police ring tones.

    This error does not occur in the list "settings > sounds and haptic > ringtones.

    I have attached a picture and highlights the different font size to display errors. Did anyone else encounter this problem or know a way to fix it?

    I just checked it on my phone and I see the same thing. Very temporarily fixed (while this isn't a convenient temporary solution) leaving the Contacts application and immediately by going to settings > brightness and view > text size, change the size and returning then immediately to the Contacts application. Update the fonts and all options are the same size, but as soon as you press Cancel and return to a ring tone, it will be inconsistent again.

  • Safari 10: too small font size

    After the installation of Safari 10.0 this morning, nothing is as it used to be - printing on most websites is too small for me to read. The option to adjust the size to a minimum size by default in the Preferences window has disappeared; pages can be enlarged in 125, 150% etc but not what I want.

    I no has not upgraded to the latest version of Safari to end up reading texts too small they are printed on stamps!

    Do these guys at apple all this walk with a watchmakers eyepiece? All solutions (style sheets?)?

    There are a number of discussions on this issue with your same concern. I agree, the issue of font size is really bad and the zoom function is NOT a way to solve this problem. As others have suggested sending back to Apple is a way of approaching the question with the hope that they give the choice of font size in preferences rather than this impassable zoom feature.

  • Font size in safari

    Download Safari 10.0 and os 10.12 size police and the darkness of the police do I have very difficult for me to see.  Is there a way to change this?

    There are already a number of threads on this after a day with Safari 10. This is a real problem. The Zoom feature ISN'T as the font size. I just dropped pages were illegible and pensioners via Time Machine my old system will avoid Mac Sierra until this is changed.

  • Missing in SAFARI 10.0 default font size

    Just updated to SAFARI 10.0, they removed the ability to change the default font size.  Now, the writing is too small, what can I do to fix this?

    Send feedback to Apple. They will not respond, but at least know that there is a problem or a suggestion for change. If enough people send feedback, it can get change / suggested the problem solved as soon as possible.

    Your comments

  • In Safari 10 minimum font size

    Hi people,

    Is there a way to restore the minimum font size setting 9 Safari Safari 10? Zoom the entire page is not as useful as the increase in the minimum size of text. To return to the 18pt size I had before, I up to 150%, which increases all the parts of the page, making it too large to render correctly.

    Minimum size was certainly not perfect, but it was the best option in my situation of low vision.

    Rgds,

    There is circumvention via CSS custom solutions, you can find online.

    I am facing the same problem and have sent feedback to Apple. It borders on the hostile user behaviour, discrimination against people with a weak eyesight and seems to be a crazy interface simplification exercise.

    My only solution is to go back to chrome until Apple decides to solve this problem.

  • Where is the minimum font size in Safari Version 10.0 (11602.1.50.0.10)?

    I need to control the font size in Safari. Apple seems to have removed. Does anyone know where the police since the previous version of Safari controls went?

    Workarounds don't work. I find myself with a page too big for my Air 13 "screen if fonts are quite large. If the Safari page fits the screen, fonts are too low.

    (insert a LOT of expletives here).

    Help!

    Just found out his omission, too!  Horrible!

    Minimum font size control has been using Safari... keys to allow the text on the pages to have a readable size.  What is happening with Apple?

    Now, perhaps, there is an extension that can do this.  OFF to get one!

  • Safari 10.0 no minimum font size setting

    Just downloaded Safari 10.0 on my Early 2011 Macbook Pro and there is a remarkable lack of functionality: definition of a minimum font size. The setting seems to be replaced by the percentage of zoom of page that is not as useful for me. Anyone know if Apple has just moved this setting or if it is gone for good?

    It seems that he's gone.

    You could try a different resolution in system preferences > monitors > display > chipped.

    Or system preferences > accessibility > Zoom.

  • The font size in Safari 10 cannot be changed

    I'm blind, or y at - it ideas?

    I'll be blind if they don't remedy. Several people in the other thread too unhappy.

    Zoom is not the same as the font size. I need size of 16 points to read.

  • How to set the FONT SIZE on Safari 10?

    I use OS X 10.11.6, and I just downloaded Safari 10.0. He seems to have replaced the 'minimum font size' with a "zoom" feature but there is a big problem: if I as large font size that I prefer, the page runs off the screen; If I do the optimal zoom page, the police is too small! So I have to squint as soon as the text continue to slide backwards to see the entire page. It's annoying and stupid. Is there a way to adjust the size of police ALONE?

    Have the same question. Safari 10.0 is USELESS to me if I can't change the font size. Never thought Apple would make such Microsoft (see IE) thing.

  • Font size of mail to small to read

    I have an i-Phone 5 just update to ios 10. The size of the text in incoming mail is so small that it is unreadable. If I Zoom on the message, the text becomes large enough to read, but you have to scroll back to follow a line of text. Prior to the update of the size of the text was very good. Does anyone have a solution to this? It is virtually unusable as-is.

    Hello. Unfortunately there is no way to change just the font in Mail on iOS 10, but you can change the font size in the full operating system. If you go to settings-> general-> accessibility-> larger text. From there you can enable this feature. You can then adjust the size of the font on iOS 10. See this article for more information:

    Change the font size on your iPhone, iPad and iPod touch - Apple Support

    Hope this helps

Maybe you are looking for