All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.harmony.awt.gl.font.LineMetricsImpl Maven / Gradle / Ivy

The newest version!
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/**
 * @author Ilya S. Okomin
 */
package org.apache.harmony.awt.gl.font;


import org.apache.harmony.awt.internal.nls.Messages;

import com.google.code.appengine.awt.font.LineMetrics;


/**
 *
 * LineMetrics implementation class.
 */

public class LineMetricsImpl extends LineMetrics implements Cloneable{

    // array of baseline offsets
    float[] baselineOffsets;

    // the number of characters to measure
    int numChars;

    // baseline index of the font corresponding to this line metrics
    int baseLineIndex;

    // underline thickness
    float underlineThickness;

    // underline offset
    float underlineOffset;

    // strikethrough thickness
    float strikethroughThickness;

    // strikethrough offset
    float strikethroughOffset;

    // External leading
    float leading;

    // Height of the font ( == (ascent+descent+leading))
    float height;

    // Ascent of the font
    float ascent;

    // Descent of the font
    float descent;

    // Width of the widest char in the font
    float maxCharWidth;

    // underline thickness (in pixels)
    int lUnderlineThickness;

    // underline offset (in pixels)
    int lUnderlineOffset;

    // strikethrough thickness (in pixels)
    int lStrikethroughThickness;

    // strikethrough offset (in pixels)
    int lStrikethroughOffset;

    // External leading (in pixels)
    int lLeading;

    // Height of the font ( == (ascent+descent+leading)) (in pixels)
    int lHeight;

    // Ascent of the font (in pixels)
    int lAscent;
    
    // Descent of the font (in pixels)
    int lDescent;

    //  Width of the widest char in the font (in pixels)
    int lMaxCharWidth;

    // units per EM square in font value
    int units_per_EM = 0;

    /**
     * Creates LineMetricsImpl object from specified parameters. If baseline data parameter
     * is null than {0, (-ascent+descent)/2, -ascent} values are used for baseline offsets.
     *  
     * @param len a number of characters 
     * @param metrics an array of 16 elements with metrics values that can be 
     * initialized in native code.

* metrics[0] - ascent

* metrics[1] - descent

* metrics[2] - external leading

* metrics[3] - underline thickness

* -metrics[4] - underline offset

* metrics[5] - strikethrough thickness

* -metrics[6] - strikethrough offset

* metrics[7] - maximum char width

* metrics[8] - ascent in pixels

* metrics[9] - descent in pixles

* metrics[10] - external leading in pixels

* metrics[11] - underline thickness in pixels

* -metrics[12] - underline offset in pixels

* metrics[13] - strikethrough thickness in pixels

* -metrics[14] - strikethrough offset in pixels

* metrics[15] - maximum char width in pixels

* @param _baselineData an array of 3 elements with baseline offsets metrics

* _baselineData[0] - roman baseline offset

* _baselineData[1] - center baseline offset

* _baselineData[2] - hanging baseline offset

*/ public LineMetricsImpl(int len, float[] metrics, float[] _baselineData){ if (metrics.length < 16){ // awt.40=Wrong number of metrics\! throw new IllegalArgumentException(Messages.getString("awt.40")); //$NON-NLS-1$ } numChars = len; ascent = metrics[0]; // Ascent of the font descent = metrics[1]; // Descent of the font leading = metrics[2]; // External leading if (_baselineData == null){ baseLineIndex = 0; baselineOffsets = new float[]{0, (-ascent+descent)/2, -ascent}; } else { baseLineIndex = (int)_baselineData[3]; baselineOffsets = new float[3]; System.arraycopy(_baselineData, 0, baselineOffsets, 0, 3); } height = metrics[0] + metrics[1] + metrics[2]; // Height of the font ( == (ascent + descent + leading)) underlineThickness = metrics[3]; underlineOffset = -metrics[4]; strikethroughThickness = metrics[5]; strikethroughOffset = -metrics[6]; maxCharWidth = metrics[7]; lAscent = (int)metrics[8]; // Ascent of the font lDescent = (int)metrics[9]; // Descent of the font lLeading = (int)metrics[10]; // External leading lHeight = lAscent + lDescent + lLeading; // Height of the font ( == (ascent + descent + leading)) lUnderlineThickness = (int)metrics[11]; lUnderlineOffset = - (int)metrics[12]; lStrikethroughThickness = (int)metrics[13]; lStrikethroughOffset = -(int)metrics[14]; lMaxCharWidth = (int)metrics[15]; } /** * Creates LineMetricsImpl object from specified parameters. If baseline data parameter * is null than {0, (-ascent+descent)/2, -ascent} values are used for baseline offsets. * * @param _numChars number of chars * @param _baseLineIndex index of the baseline offset * @param _baselineOffsets an array of baseline offsets * @param _underlineThickness underline thickness * @param _underlineOffset underline offset * @param _strikethroughThickness strikethrough thickness * @param _strikethroughOffset strinkethrough offset * @param _leading leading of the font * @param _height font height * @param _ascent ascent of the font * @param _descent descent of the font * @param _maxCharWidth max char width */ public LineMetricsImpl(int _numChars, int _baseLineIndex, float[] _baselineOffsets, float _underlineThickness, float _underlineOffset, float _strikethroughThickness, float _strikethroughOffset, float _leading, float _height, float _ascent, float _descent, float _maxCharWidth) { numChars = _numChars; baseLineIndex = _baseLineIndex; underlineThickness = _underlineThickness; underlineOffset = _underlineOffset; strikethroughThickness = _strikethroughThickness; strikethroughOffset = _strikethroughOffset; leading = _leading; height = _height; ascent = _ascent; descent = _descent; baselineOffsets = _baselineOffsets; lUnderlineThickness = (int) underlineThickness; lUnderlineOffset = (int) underlineOffset; lStrikethroughThickness = (int) strikethroughThickness; lStrikethroughOffset = (int) strikethroughOffset; lLeading = (int) leading; lHeight = (int) height; lAscent = (int) ascent; lDescent = (int) descent; maxCharWidth = _maxCharWidth; } public LineMetricsImpl(){ } /** * All metrics are scaled according to scaleX and scaleY values. * This function helps to recompute metrics according to the scale factors * of desired AffineTransform. * * @param scaleX scale X factor * @param scaleY scale Y factor */ public void scale(float scaleX, float scaleY){ float absScaleX = Math.abs(scaleX); float absScaleY = Math.abs(scaleY); underlineThickness *= absScaleY; underlineOffset *= scaleY; strikethroughThickness *= absScaleY; strikethroughOffset *= scaleY; leading *= absScaleY; height *= absScaleY; ascent *= absScaleY; descent *= absScaleY; if(baselineOffsets == null) { getBaselineOffsets(); } for (int i=0; i< baselineOffsets.length; i++){ baselineOffsets[i] *= scaleY; } lUnderlineThickness *= absScaleY; lUnderlineOffset *= scaleY; lStrikethroughThickness *= absScaleY; lStrikethroughOffset *= scaleY; lLeading *= absScaleY; lHeight *= absScaleY; lAscent *= absScaleY; lDescent *= absScaleY; maxCharWidth *= absScaleX; } /** * Returns offset of the baseline. */ @Override public float[] getBaselineOffsets() { // XXX: at the moment there only horizontal metrics are taken into // account. If there is no baseline information in TrueType font // file default values used: {0, -ascent, (-ascent+descent)/2} return baselineOffsets; } /** * Returns a number of chars in specified text */ @Override public int getNumChars() { return numChars; } /** * Returns index of the baseline, one of predefined constants. */ @Override public int getBaselineIndex() { // Baseline index is the deafult baseline index value // taken from the TrueType table "BASE". return baseLineIndex; } /** * Returns thickness of the Underline. */ @Override public float getUnderlineThickness() { return underlineThickness; } /** * Returns offset of the Underline. */ @Override public float getUnderlineOffset() { return underlineOffset; } /** * Returns thickness of the Strikethrough line. */ @Override public float getStrikethroughThickness() { return strikethroughThickness; } /** * Returns offset of the Strikethrough line. */ @Override public float getStrikethroughOffset() { return strikethroughOffset; } /** * Returns the leading. */ @Override public float getLeading() { return leading; } /** * Returns the height of the font. */ @Override public float getHeight() { return height; // equals to (ascent + descent + leading); } /** * Returns the descent. */ @Override public float getDescent() { return descent; } /** * Returns the ascent. */ @Override public float getAscent() { return ascent; } /** * Returns logical thickness of the Underline. */ public int getLogicalUnderlineThickness() { return lUnderlineThickness; } /** * Returns logical offset of the Underline. */ public int getLogicalUnderlineOffset() { return lUnderlineOffset; } /** * Returns logical thickness of the Strikethrough line. */ public int getLogicalStrikethroughThickness() { return lStrikethroughThickness; } /** * Returns logical offset of the Strikethrough line. */ public int getLogicalStrikethroughOffset() { return lStrikethroughOffset; } /** * Returns the logical leading. */ public int getLogicalLeading() { return lLeading; } /** * Returns the logical height of the font. */ public int getLogicalHeight() { return lHeight; // equals to (ascent + descent + leading); } /** * Returns the logical descent. */ public int getLogicalDescent() { return lDescent; } /** * Returns the logical ascent. */ public int getLogicalAscent() { return lAscent; } /** * Returns the logical size of the widest char. */ public int getLogicalMaxCharWidth() { return lMaxCharWidth; } /** * Returns the size of the widest char. */ public float getMaxCharWidth() { return maxCharWidth; } /** * Set num chars to the desired value. * * @param num specified number of chars */ public void setNumChars(int num){ numChars = num; } @Override public Object clone(){ try{ return super.clone(); }catch (CloneNotSupportedException e){ return null; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy