Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calculate String Length in Pixels

Thijs Franck-OracleNov 4 2015 — edited Nov 4 2015

Hi everyone,

I recently started to look into APEX for my project, so I'm still very much learning the basics. One of my requirements is to calculate the length of a String in pixels and update the status of my item based on the result. The use case is to perform this calculation when the user uploads a csv file to the database. So, for a given font, style and size, the function returns the length of a String in pixels. My perception is that this could best be implemented as either a transformation during data loading or as a database trigger on insert. Since my other option is ADF, I implemented the calculation in Java as a proof of concept. I would like to know whether this is also possible in PL/SQL (I know it is possible in javascript, but during data loading returning a result from a javascript function is not an option).

package measurer;

import java.awt.Font;

import java.awt.FontMetrics;

import java.awt.image.BufferedImage;

public class Measurer {

   

    private BufferedImage img = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);

    private FontMetrics fm;

   

    public Measurer(Font f){

        setFont(f);

    }

   

    public int measure(String text){

        return fm.stringWidth(text);

    }

    public void setFont(Font f) {

        fm = img.getGraphics().getFontMetrics(f);       

    }

   

    public Font getFont(){

        return fm.getFont();

    }

}

Thank you for your input!

Regards,

Thijs

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2015
Added on Nov 4 2015
4 comments
1,629 views