forked from geodmms/xdgnjobs

?? ?
2008-05-17 8713611a01ee773ff9630a0af084422a0765cb90
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/io/dgn7/TextElement.java
@@ -1,11 +1,10 @@
package com.ximple.io.dgn7;
//~--- non-JDK imports --------------------------------------------------------
import java.awt.geom.AffineTransform;
import org.apache.log4j.Logger;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
@@ -30,32 +29,33 @@
    //  Enter data field left justification
    public static final int ED_RIGHTJUSTIFICATION = 0;
    //  Enter data field right justification
    public static final int TXTJUST_CB = 0;
    public static final int TXTJUST_LT = 0;    /* Left Top */
    public static final int TXTJUST_LC = 1;    /* Left Center */
    public static final int TXTJUST_LB = 2;    /* Left Bottom */
    public static final int TXTJUST_LMT = 3;   /* Left Margin Top */
    public static final int TXTJUST_LMC = 4;   /* Left Margin Center */
    public static final int TXTJUST_LMB = 5;   /* Left Margin Bottom */
    public static final int TXTJUST_CT = 6;    /* Center Top */
    public static final int TXTJUST_CC = 7;    /* Center Center */
    public static final int TXTJUST_CB = 8;    /* Center Bottom */
    public static final int TXTJUST_RMT = 9;   /* Right Margin Top */
    public static final int TXTJUST_RMC = 10;  /* Right Margin Center */
    public static final int TXTJUST_RMB = 11;  /* Right Margin Bottom */
    public static final int TXTJUST_RT = 12;   /* Right Top */
    public static final int TXTJUST_RC = 13;   /* Right Center */
    public static final int TXTJUST_RB = 14;   /* Right Bottom */
    //  Center/bottom text justification.
    public static final int TXTJUST_CC = 0;
    //  Center/center text justification.
    public static final int TXTJUST_CT = 0;
    //  Center/top text justification.
    public static final int TXTJUST_LB = 0;
    //  Left/bottom text justification.
    public static final int TXTJUST_LC = 0;
    //  Left/center text justification.
    public static final int TXTJUST_LT = 0;
    //  Left/top text justification.
    public static final int TXTJUST_RB = 0;
    //  Right/bottom text justification.
    public static final int TXTJUST_RC = 0;
    //  Right/center text justification.
    public static final int TXTJUST_RT = 0;
    public static final int TXTJUST_LU = 15;   /* Left Cap */
    public static final int TXTJUST_LD = 16;   /* Left Descender */
    public static final int TXTJUST_LMU = 17;  /* Left Margin Cap */
    public static final int TXTJUST_LMD = 18;  /* Left Margin Descender */
    public static final int TXTJUST_CU = 19;   /* Center Cap */
    public static final int TXTJUST_CD = 20;   /* Center Descender */
    public static final int TXTJUST_RMU = 21;  /* Right Margin Cap */
    public static final int TXTJUST_RMD = 22;  /* Right Margin Descender */
    public static final int TXTJUST_RU = 23;   /* Right Cap */
    public static final int TXTJUST_RD = 24;   /* Right Descender */
    public static final int TXTJUST_NONE = 127;/* no justfication */
    public TextElement(byte[] raw)
    {
@@ -76,84 +76,6 @@
        double dy = DgnUtility.converUnitToCoord(y);
        return new Coordinate(dx, dy);
    }
    public Coordinate getUserOrigin()
    {
        Coordinate origin = getOrigin();
        double x = origin.x;
        double weight = getUserSetWeight();
        double height = getUserSetHeight();
        double angle = DgnUtility.converRotationToRadian(getRotationAngle());
        x += weight * Math.cos(angle) - height * Math.sin(angle);
        double y = origin.y;
        y += weight * Math.cos(angle) - height * Math.sin(angle);
        return new Coordinate(x, y);
    }
    private double getUserSetWeight()
    {
        int just = getJustification();
        Envelope range = getRange();
        double weight = (range.getWidth());
        switch (just)
        {
        case 0:
        case 1:
        case 2:
            weight = 0;
            break;
        case 6:
        case 7:
        case 8:
            weight = weight / 2;
            break;
        case 12:
        case 13:
        case 14:
            break;
        }
        return weight;
    }
    private double getUserSetHeight()
    {
        int just = getJustification();
        double height = getTextHeight();
        switch (just)
        {
        case 2:
        case 8:
        case 14:    // bottom
            height = 0;
            break;
        case 1:
        case 7:
        case 13:    // center
            height = height / 2;
            break;
        case 0:
        case 6:
        case 12:    // height
            break;
        }
        return height;
    }
    public int getFontIndex()
@@ -211,10 +133,7 @@
    public double getRotationAngle()
    {
        int totation = ((raw[23] << 16) & 0xffff0000);
        totation += raw[24] & 0x0000ffff;
        int totation = ((raw[23] & 0x0000ffff) << 16) | (raw[24] & 0x0000ffff);
        return DgnUtility.converIntToRotation(totation);
    }
@@ -269,6 +188,88 @@
        return factory.createPoint(getUserOrigin());
    }
    private double getUserWidth()
    {
        int just = getJustification();
        // Envelope range = getRange();         // case -1
        // double width = (range.getWidth());   // case -1
        // double width = this.getTextWidth() * this.getTextLength() * 1000.0; // case -2
        double width = (this.getTextWidth() * this.getTextLength());
        switch (just)
        {
        case TXTJUST_LT:
        case TXTJUST_LC:
        case TXTJUST_LB:
            width = 0;
            break;
        case TXTJUST_CT:
        case TXTJUST_CC:
        case TXTJUST_CB:
            width = width / 2;
            break;
        case TXTJUST_RT:
        case TXTJUST_RC:
        case TXTJUST_RB:
            break;
        }
        return width;
    }
    private double getUserHeight()
    {
        int just = getJustification();
        double height = getTextHeight();
        switch (just)
        {
        case TXTJUST_LB:
        case TXTJUST_CB:
        case TXTJUST_RB:    // bottom
            height = 0;
            break;
        case TXTJUST_LC:
        case TXTJUST_CC:
        case TXTJUST_RC:    // center
            height = height / 2;
            break;
        case TXTJUST_LT:
        case TXTJUST_CT:
        case TXTJUST_RT:    // height
            break;
        }
        return height;
    }
    public Coordinate getUserOrigin()
    {
        double width = getUserWidth();
        double height = getUserHeight();
        double angle = Math.toRadians(getRotationAngle());
        AffineTransform at = new AffineTransform();
        at.translate(width, height);
        Coordinate p = getOrigin();
        at.setToRotation(angle, p.x, p.y);
        at.scale(1, 1);
        double[] srcPt = new double[2];
        double[] dstPt = new double[2];
        srcPt[0] = p.x + width ;
        srcPt[1] = p.y + height ;
        at.transform(srcPt, 0, dstPt, 0, 1);
        return new Coordinate(dstPt[0], dstPt[1]);
    }
    public static class ElementHandler extends Element.ElementHandler
    {
        private static ElementHandler instance = null;