Bounding box for text

Howdy, I am looking for a way to get the bounding box of some text. I can do it with a graphics2d object, but there are some times when I want to get the bounding box without having access to a graphics objects. I have looked at several classes in the API and it seems that they either take a graphics object or one of their parameters takes a graphics object (Parameter A uses a graphics object of method A, for example). Is there a way to do it without one?
Thanks.
Message was edited by:
dayrinni

See the caution in paragraph four of the FontRenderContext comments.
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.Rectangle2D;
import javax.swing.*;
public class NoGraphics {
    public static void main(String[] args) {
        String s = "Hello World";
        FontRenderContext frc = new FontRenderContext(null, false, false);
        Font font = new Font("dialog", Font.PLAIN, 36);
        GlyphVector gv = font.createGlyphVector(frc, s);
        Rectangle2D r1 = font.getStringBounds(s, frc);
        Rectangle2D r2 = new TextLayout(s, font, frc).getBounds();
        Rectangle2D r3 = gv.getLogicalBounds();
        Rectangle2D r4 = gv.getPixelBounds(frc, 0, 0);
        Rectangle2D r5 = gv.getVisualBounds();
        System.out.printf("%s%n%s%n%s%n%s%n%s%n", toString(r1, "string"),
                           toString(r2, "text"),  toString(r3, "logical"),
                           toString(r4, "pixel"), toString(r5, "visual"));
        final JLabel position = new JLabel("x = 0  y = 0", JLabel.CENTER);
        JLabel label = new JLabel(s, JLabel.CENTER);
        label.setFont(font);
        label.setText(s);
        label.setOpaque(true);
        label.setBackground(Color.pink);
        label.addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseMoved(MouseEvent e) {
                position.setText("x = " + e.getX() + "  y = " + e.getY());
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(2,2,2,2);
        gbc.gridwidth = gbc.REMAINDER;
        panel.add(label, gbc);
        panel.add(position, gbc);
        JOptionPane.showMessageDialog(null, panel, "Compare",
                                      JOptionPane.PLAIN_MESSAGE);
    private static String toString(Rectangle2D r, String id) {
        return String.format("%8s [%.1f, %.1f]",
                              id, r.getWidth(), r.getHeight());
}

Similar Messages

  • Trying to create box for text but....

    Hi all.
    So I am new to the software.  What I am trying to do is create a box for text.  I want it to be "above" the background so that the background color does not color in the back of the text box.
    An example can be found http://www.tree.com/
    At the "about tree.com" that is (a more coloful, rounded version) of what I am looking for. It is a very common thing to see in sites, I just can't figure it out.
    Thanks,
    Patrick

    Patrick
    Your question is so basic it really requires a fairly lengthy answer, the best advice is for you to find a beginner totorial on html/css. The software is really just a tool, but you really need to understand the underlying code..
    Text, as well as all content sits in elements, which reside in the body of the html code. Each element has its own properties, such as a background color or image. (not to mention the content has its own stylings)  These are set in the CSS (Cascading Style Sheets). So to give you an anwer to your question is not that simple.
    So best adviced is to google beginner HTML/CSS and see what pops up.
    HTH
    Gary

  • Convert jpg to pdf with proper bounding box for LaTeX

    Hi,
    does anybody know how I can use Acrobat 8 Professional on my Mac to convert a jpg into a pdf that with a proper bounding box for LaTeX?
    When I import the jpg and save it as a pdf, then LaTeX cannot determine the correct size, and, therefore, the picture appears way too big in LaTeX's output.
    The LaTeX Error message is "Cannot determine size of graphic in myPic.pdf (no BoundingBox)"
    On my Mac I don't even know how to check the size of the bounding box.
    Thanks for your suggestions!
    Kurt

    Hi - thanks for all the answers.
    I have tried to use Graphics Converter but it has way too many options, and if I just use the default one's, the pdf quality is changed, so black does not appear as black anymore but slightly grey. And since Graphics Converter changed the pdf unexpectedly, I don't want to risk that it changes something else that I might miss now and only realize when the manuscript is in print.
    Currently, I cannot check if the correct Bounding Box would be set using Graphics Converter: My LaTeX implementation shows the pdf in the correct size, even without bounding box, but the LaTeX implementation of the journal I am submitting the graphics to does not, and since I already submitted the manuscript, I cannot check anymore. Using GhostView on a PC would help, but on a Mac I don't get GhostScript to do that.
    I cannot use jpg's directly, as the journal does not support jpg's.
    The figures were prepared using photoshop, so maybe I try exporting them directly from there, but as far as I remember, this did not set the bounding box correctly either. But since I am not sure I need to test it again.
    Is there a way to view the bounding box?
    I thought that the bounding box just gives the dimensions in pixels, so does the actual size really matter?
    Thanks a lot.
    Kurt

  • How to get bounds of bounding box of text item.

    Hi all,
    I am trying to get the bounds of bounding box of paragraph text item. I found the following link,
    the coordinate of a bounding box is the same as the layer's coordinate?
    But the solution doesn't work for me. It gives me the layer's bound every time i.e. the bounds of actual text.
    Can someone have any idea how to accomplish this?
    Thanks.

    It's a known "not trivial". You have layer.textItem.width/height, but they don't always report correct values. I.e. if the layer or doc has been resized, those values are missing scale multipliers. Worse it's works differently wrong in different versions of CC and Mac/Win. What I use is below (with some utility functions missing), but it's just CC 2012 and 2014 (CS6 is just bounds).
    Alternatively you can get this stuff on Action Manager only, but I'm not familiar enough and let other comment on it.
    Photoshop = {
      getTextExtents: function (layer) {
      if (layer && layer.textItem) {
      var text_item = layer.textItem
      if (Photoshop.isCC2014() || (Photoshop.isMac() && Photoshop.isCC2012())) { // in mac the newer method is correct also in CC2012
      return Photoshop._getTextExtentsCC2014(text_item)
      } else if (Photoshop.isCC2012()) {
      return Photoshop._getTextExtentsCC2012(text_item)
      } else {
      return Photoshop._getTextExtentsCS6(text_item)
      _getTextExtentsCC2014: function (text_item) {
      app.activeDocument.activeLayer = text_item.parent
      var ref = new ActionReference()
      ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") )
      var action = executeActionGet(ref)
      //Photoshop._debugActionKeys(action)
      var textKey = action.getObjectValue(stringIDToTypeID('textKey'))
      var bounds = textKey.getObjectValue(stringIDToTypeID('bounds'))
      var width = bounds.getUnitDoubleValue (stringIDToTypeID('right'))
      var height = bounds.getUnitDoubleValue (stringIDToTypeID('bottom'))
      var x_scale = 1
      var y_scale = 1
      if (textKey.hasKey(stringIDToTypeID('transform'))) { 
      var transform = textKey.getObjectValue(stringIDToTypeID('transform'))
      x_scale = transform.getUnitDoubleValue (stringIDToTypeID('xx'))
      y_scale = transform.getUnitDoubleValue (stringIDToTypeID('yy'))
      x_scale *= width / text_item.width
      y_scale *= height / text_item.height
      return {
      x:Math.round(text_item.position[0]),
      y:Math.round(text_item.position[1]),
      width:Math.round(width*x_scale),
      height:Math.round(height*y_scale) }
      _getTextExtentsCC2012: function(text_item) {
      app.activeDocument.activeLayer = text_item.parent
      var ref = new ActionReference()
      ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") )
      var action = executeActionGet(ref)
      var textKey = action.getObjectValue(stringIDToTypeID('textKey'))
      //Photoshop._debugActionKeys(textKey)
      var bounds = textKey.getObjectValue(stringIDToTypeID('bounds')) 
      var width = bounds.getUnitDoubleValue (stringIDToTypeID('right')) 
      var height = bounds.getUnitDoubleValue (stringIDToTypeID('bottom')) 
      var x_scale = 1
      var y_scale = 1
      if (textKey.hasKey(stringIDToTypeID('transform'))) { 
      var transform = textKey.getObjectValue(stringIDToTypeID('transform'))
      x_scale = transform.getUnitDoubleValue (stringIDToTypeID('xx'))
      y_scale = transform.getUnitDoubleValue (stringIDToTypeID('yy'))
      return {
      x:Math.round(text_item.position[0]),
      y:Math.round(text_item.position[1]),
      width:Math.round(width*x_scale),
      height:Math.round(height*y_scale)
      _getTextExtentsCS6: function (text_item) {
      var layer = text_item.parent
      return {
      x:Photoshop.getLayerLeft(layer),
      y:Photoshop.getLayerBottom(layer),
      width:Photoshop.getLayerWidth(layer),
      height:Photoshop.getLayerHeight(layer)

  • Bounding box for point and radius

    I am using google maps and WGS 84 (4326).
    I am trying to get the bounding box that contains a circle of a given radius in miles starting at a given lat/lon.
    I saw SDO_GEOM.SDO_MBR, but I wasn't sure how to do the circle (or at the least get points m miles north, south, east, and west of a given point)

    that works.
    I am using PHP and OCI8 So, I also used SDO_UTIL.TO_WKTGEOMETRY to get a text version of the box that I then parsed in PHP. Otherwise, it would not give me the value of the box.
                   SELECT SDO_UTIL.TO_WKTGEOMETRY(SDO_GEOM.SDO_MBR(
                        SDO_GEOM.SDO_BUFFER(
                             SDO_GEOMETRY
                                       (2001, -- SDO_GTYPE attribute: 2 = 2D, 1=point
                                            <SRID HERE>,
                                            SDO_POINT_TYPE(<LON HERE>, <LAT HERE>, NULL),
                                            NULL,
                                            NULL),
                             30, -- miles
                             .05,      -- tolerance
                             'unit=mile')
                            )) box
                        from dual

  • Bounding box for selecting components

    Hi,
    in my application i have to implement a bounding box to select some displayed components (panels or icons). I have searched for a JAVA-technique for bounding boxes, but i did not found anything.
    Does anybody know a JAVA-API that supports bounding boxes ?
    Thanks for your help

    Hi,
    in my application i have to implement a bounding box to select some displayed components (panels or icons). I have searched for a JAVA-technique for bounding boxes, but i did not found anything.
    Does anybody know a JAVA-API that supports bounding boxes ?
    Thanks for your help

  • Why can't I see the bounding box for objects on the pasteboard?

    Adobe CC sucks. Why last week was I able to see the bounding box of objects that I had on the pasteboard in InDesign CC, including objects that didn't contain anything yet, and now suddenly this week I can't see them?
    It seems as though every week something inexplicably gets changed around. First Save As had no shortcut, then suddenly the shortcut is back, but it doesn't work.
    Get it together Adobe. I don't want to be paying a subscription for a product that feels as though it's still in Beta mode.

    Hi Steve,
    Yes thanks, I don't think I was clear in what I wrote. I knew that they could be turned back on, but why did I open InDesign this morning to find my workspace/preferences different than how I left them on Friday?
    And I know it isn't a case of my mistakenly turning off the frame edges, because the operator that sits next to me had the exact same thing happen to her copy of InDesign this morning also.
    I understand the requirement to update things, but it really does feel as though I'm using software that is still in testing.

  • Bounding box around Text Illustrator CS2 12 Windows XP

    My computer crashed while using Adobe Illustrator and when rebooting I have lost the bounding box when typing text. Now I am unable to resize my text. Any suggestions on how to get the bounding box back? Clicking the direct selection tool does nothing. I can outline the text but still no bounding box to grab and resize.
    Should I reinstall Illustrator? Is there a default setting to go back to? If I shut down and reboot the same problem happens.

    Is it just text objects or others, as well?
    See
    FAQ #6

  • Tick boxes for text formula

    Hello
    could someone please help me
    i have a table with names events and tick boxes and this works perfectly.
    i would like if the tick box is ticked, the name is placed in a second table.
    however,it will not place the names, only numbers
    this formula does numbers fine, just not names instead it leaves a '0'... could someone please help?
    =SUMIF(Events :: D2,TRUE,Events :: C2)
    this one leaves a TRUE or FALSE depending if it is ticket or not
    =IF(Events :: D2,TRUE,Events :: C2)
    Many thanks

    Amber,
    You seem to have posted nearly identical questions in the Mac iWork discussion and the iPad iWork discussion. In both cases, you are proposing a function that is designed to return a numeric value, a count or a sum, and you are wondering why you don't get a text result.
    Take a look at the LOOKUP functions. They will return content such as names, as you are seeking.
    What you are looking for is in the "moderate difficulty" realm of Numbers programming. Not simple, but not terribly difficult either.
    My solution would be to add one column to the main table for each subtable. i would program each of these subtable-specific new columns to display a sequence number whenever the corresponding event checkbox is TRUE for that row. Then in the "Event 1" subtable, in the row where I want the first name for that event to be transferred from the main table, I would use LOOKUP to find the number "1" in the sequence column for Event 1 in the main table. In the next row, I would return the name with the number "2" in the Event 1 column of the main table, etc.
    If this approach sounds like what you are looking for, I'd be happy to work out some formulas for you.
    Jerry

  • Save dialog box for text and pdf files

    Hi,
    I am using CRM UI framework for developing my components.
    Currently i have a hyperlink for a file. On click of the hyperlink i want the Save dialog box to appear with SAVE/OPEN/CANCEL options. For Word/Excel/PPT files, dialog box appears. However for txt/PDF files, dialog box does not appear.
    URL looks like the following:
    http://uxcia0g.wdf.sap.corp:50026/sap/bc/contentserver/000?get&pVersion=0045&contRep=RPS_DB_02&docId=80215A5C348E1DEE8A9EC8FFDED05E54&compId=chk.pdf&content_disposition=attachment.
    Could you please help me to resolve this issue?
    Regards,
    Vinay

    First of all, you need an app on the iPad that can read those files that you want to transfer. Adobe Reader and iBooks are two free apps that will read PDF files. Adobe Reader is much more robust than iBooks as it offers so many more features like renaming files, creating folders, annotating, highlights, etc.
    Download Adobe Reader in the App Store. Then read this about file sharing with iTunes.
    iOS: About File Sharing - Support - Apple
    There are other ways to get files to the iPad, like email, DropBox and some other apps that let you mount your iPad like a flash drive.
    This should be helpful as well.
    iTunes 11 for Mac: Set up syncing for iPod, iPhone, or iPad

  • No bounding box for resizing rectangles with latest Illustrator update (CC 2014 18.1.0). iMac with OS 10.8.5. Please fix.

    Lost ability to resize rectangles with latest Illustrator update. Please correct.

    The following entry may indicate a failing harddrive, so doing backups and replacing the harddrive may be in order.
    Disk Information:
              TOSHIBA MK7559GSXF disk0 : (750,16 GB)
              S.M.A.R.T. Status: Failing                                  <-----------
    A little bit about drive S.M.A.R.T. status:
    "The most basic information that SMART provides is the SMART status. It provides only two values: "threshold not exceeded" and "threshold exceeded". Often these are represented as "drive OK" or "drive fail" respectively. A "threshold exceeded" value is intended to indicate that there is a relatively high probability that the drive will not be able to honor its specification in the future: that is, the drive is "about to fail". The predicted failure may be catastrophic or may be something as subtle as the inability to write to certain sectors, or perhaps slower performance than the manufacturer's declared minimum."
    http://en.wikipedia.org/wiki/S.M.A.R.T.

  • Text put into a canvas element with context.fillText() always has a black box where each letter goes. If the text is black you just see the black rectangle. If the text is not black you see it on the black bounding box. Surely this is not right.

    This has happened on the last few versions of firefox, as long as canvas has been supported. I see other people's screen shots from canvas tutorials, and the text always looks normal. On my system, any text put into a canvas element via context.fillText() will have a black bounding box for each letter, sized appropriately for the letter. If the text is black, of course you only see rectangles. If the text is a contrasting color, then you can read it, but it looks bizarre.

    Thomas...same kind of crap here.
    I used Custom Text - entered a sentence, hit return, entered another.
    Set to 72 pt.
    The default alignment is centred - I want left aligned text...the text start point stays at the centre of frame and the sentence runs off the edge of the bounding box.
    There is no settings in the Text or Title inspector dialog to correct that!
    Using Transform will not sort it!

  • Text wrap for a paragraph: How to define the width of a Text box /  active text area? I simply need a longish text to wrap within the frame!

    Hello, I've been searching for a good while in the forums now, but have found no solution or real mention of the problem – I hope some of you can help.
    I want to very simply layout a text between scenes, a slightly longer text that wraps within the frame margins. Here's an example of how I want it to look:
    Now, I couldn't for the life of me get the Custom Text to behave like that, as there are no parameters to set for the width of the text area. The Text Size, yes, along with the Tracking, Baseline and all that, but the width of the text box, no. The above was created by customizing one of the other Text Generator presets that happened to be left aligned.
    However, this preset has a fade in/fade out transition, which I do not want. There's no way to remove this transition as it seems integrated into the Text Generator (meaning they are not really presets, but separate kinds of Text objects? Very silly.)
    So I am asking you: Is there any way to get the Custom Text generator to behave like that? Just a text paragraph as above. Below you'll see all I can manage with the diffferent Custom Text parameters. Any kind of repositioning and resizing of the text just changes the position and size of the frame – but the actual text items are just cropped off where they extend out of that frame. Apparently the bounding box for the text is just some default length, and I can't find any way to adjust the width. See below my different attempts.
    The same text pasted into a Custom Text generator clearly extends outside the frame:
    Here Transform just moves – or resizes – the video frame that the Text Box exists inside:
    The Crop gives similar results, and of course Distort doesn't get me closer to what I need, either. There should be simply a Text Box Width parameter to set somewhere, but if it exists they have hidden it very well. How do you do it?
    Thanks for any help, this is a silly problem, but one of now many trivial problems that amount to me growing quite dissatisfied with FCPX. Hopefully I've just overlooked something.
    All the best,
    Thomas

    Thomas...same kind of crap here.
    I used Custom Text - entered a sentence, hit return, entered another.
    Set to 72 pt.
    The default alignment is centred - I want left aligned text...the text start point stays at the centre of frame and the sentence runs off the edge of the bounding box.
    There is no settings in the Text or Title inspector dialog to correct that!
    Using Transform will not sort it!

  • Bounding Box Overlap Print Issues - Very FRUSTRATED?

    Someone with more knowledge than I, please help.
    I have created several works in AI. In nearly all of them I've had issues printing to .pdf especially when the bounding boxes for my text elements overlap each other.
    The result when printed is an occluding/blocking/masking of the text so that the color is not correct and there is a clear line where the bounding box is overlapping the text elements.
    This seems to be happening regardless if the two text boxes are in the same layer or separate layers.
    For the life of me I can't figure out how to make this a NON-issue.
    Can someone please provide me with an answer. I have a deadline to meet and this is driving me out of my mind.
    Thank you. Thank you.

    Any way you could post a screen shot of the problem?  Is text getting clipped?  Not sure if a bounding box would effect anything related to color.  I usually apply a locked holding line around the document ( i.e., if the document is 8.5 x 11", create a holding line [ rectangle ] 8.5 x 11 with no stroke, no fill ).  Then, the PDF will technically hold all of the contents without anything getting clipped.

  • Bounding Box Doesn't Match Object (Illustrator CS4)

    I'm not sure if this is an error on my part or a bug, but for the last week or so, the bounding box for my objects hasn't actually matched the objects. This is really problematic when I try to transform the object using the bounding box handles.
    On occasion, after I transform the object the bounding box will match it again and will transform correctly. Sometimes it will stay off. If it does reorient itself, undoing the transformations back the original size will cause the bounding box to reset back to it's mismatched state.
    Things I have tried to resolve the issue:
    Reset the Bounding Box
    Copying and pasting the shape to a different document
    Starting a new document from scratch (I thought it was possible I corrupted the file)
    Return Keyboard Shortcuts to the Default
    Restarting Illustrator
    Restarting my System
    To my knowledge, my system hasn't been updated in the last week nor has anything new been installed. However, IT does push out maintenance so there is a possibiltiy that it was updated and I don't know about it. The only programs open while working in Illustrator are Bridge, Outlook 2007, IE8, Explorer, InDesign CS4, Word 2007, Photoshop CS4, Acrobat Professional 9, Dreamweaver CS4, PowerPoint 2007, Previewer and possibly FireFox 3.something (though not necessarily all at once - generally about 7 of the above listed). My system runs XP Professional SP3 with an Intel Core2 Quad @ 2.66GHz and 3.25 GB of RAM. The objects are not grouped, do not contain clipping masks, do not contain transparency masks and are not compound paths. They are simple paths/shapes, often rectangles.
    I have included some pictures to better explain my issue. This first image indicates how the bounding box doesn't match the rectangle.
    The second image shows the process of transforming the shape via dragging.
    The third image shows the result.
    Thanks for any help you can provide!

    Mr. Bugge:
    Thank you for your response and I apologize for the delay in mine. I couldn't try all of the fixes immediately because I had to complete some job duties before I could tinker with this issue.
    Things that did not work:
    Closing Firefox
    Clearing the Preferences
    Moving the Preferences Folder
    Deleting Temp Files
    Closing Other Adobe Programs (Including Bridge Running in the Background
    Things I cannot do for various reasons:
    Re-installing Acrobat
    Turning Off the Firewall (My Company Only Uses 1 Anyway)
    Things I haven't tried yet but hope to try later:
    Update Printer Definition or Change Default Printer
    Check for Corrupt Fonts
    Clear My Font Cache
    Things I learned:
    The issue is most easily recreated by transforming an object to a smaller object. However, zooming in will realign the bounding box but it will only stay aligned when zoomed in. I find it very curious.
    Even if I don't end up finding an answer, I do appreciate your time and help.

Maybe you are looking for

  • Pass function name as parameter in SSRS expression

    I have a function (GetColumnFieldName) which returns string datatype Now I want to use this function in below SSRS expression =Code.GetDisplay("FirstName",Parameters!SelectedCols.Value,Parameters!DisplayCols.Value) At the above expression I want to r

  • Difference Between Using MVC And SwingUtilities For GUI Component Update

    Hi Guys, What are the difference of using the MVC (Model View Controler) pattern to update GUI and using the SwingUtilities of doing the same job? Are there any big differences or shortcomings of any? Thanks.

  • Error ORA-29855:

    when i try to create index ihave an error below this: ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine ORA-20000: ConText error: DRG-11422: linguistic initialization failed DRG-00100: internal error, arguments : [52100],[drxf.c],

  • Need to create multiple PA documents during billing

    Hello, We have the following scenario. When we create a billing document from an SD order, we need to create multiple PA documents based on the condition types.  We have maintained those condition types to different value fields in KE4I. For e.g, for

  • How to hide a empty table using Javascript?

    Hello! I'm using Adobe LiveCylce Desinger integrated in SAP. I have a task to hide a database-table, if the table empty is. Normmaly we can do following to check, whether the content empty is. if (this.REMARK_TEXT.rawValue == null ) this.presence = "