aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/afp/AFPRectanglePainter.java
blob: 81915a19017b7806c728405267f334a761c0990c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * 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.
 */

/* $Id$ */

package org.apache.fop.afp;

import java.awt.geom.AffineTransform;

import org.apache.fop.afp.modca.DataStream;

public class AFPRectanglePainter extends AbstractAFPPainter {

    /**
     * Main constructor
     *
     * @param state the AFP painting state
     * @param dataStream the afp datastream
     */
    public AFPRectanglePainter(AFPPaintingState state, DataStream dataStream) {
        super(state, dataStream);
    }

    /** {@inheritDoc} */
    public void paint(PaintInfo paintInfo) {
        RectanglePaintInfo rectanglePaintInfo = (RectanglePaintInfo)paintInfo;
        int pageWidth = dataStream.getCurrentPage().getWidth();
        int pageHeight = dataStream.getCurrentPage().getHeight();

        AFPUnitConverter unitConv = state.getUnitConverter();
        float width = unitConv.pt2units(rectanglePaintInfo.getWidth());
        float height = unitConv.pt2units(rectanglePaintInfo.getHeight());
        float x = unitConv.pt2units(rectanglePaintInfo.getX());
        float y = unitConv.pt2units(rectanglePaintInfo.getY());

        AffineTransform at = state.getData().getTransform();

        AFPLineDataInfo lineDataInfo = new AFPLineDataInfo();
        lineDataInfo.color = state.getColor();
        lineDataInfo.rotation = state.getRotation();
        lineDataInfo.thickness = Math.round(height);

        switch (lineDataInfo.rotation) {
        case 0:
            lineDataInfo.x1 = Math.round((float)at.getTranslateX() + x);
            lineDataInfo.y1 = lineDataInfo.y2 = Math.round((float)at.getTranslateY() + y);
            lineDataInfo.x2 = Math.round((float)at.getTranslateX() + x + width);
            break;
        case 90:
            lineDataInfo.x1 = Math.round((float)at.getTranslateY() + x);
            lineDataInfo.y1 = lineDataInfo.y2
                = pageWidth - Math.round((float)at.getTranslateX()) + Math.round(y);
            lineDataInfo.x2 = Math.round(width + (float)at.getTranslateY() + x);
            break;
        case 180:
            lineDataInfo.x1 = pageWidth - Math.round((float)at.getTranslateX() - x);
            lineDataInfo.y1 = lineDataInfo.y2 = pageHeight - Math.round((float)at.getTranslateY() - y);
            lineDataInfo.x2 = pageWidth - Math.round((float)at.getTranslateX() - x - width);
            break;
        case 270:
            lineDataInfo.x1 = pageHeight - Math.round((float)at.getTranslateY() - x);
            lineDataInfo.y1 = lineDataInfo.y2 = Math.round((float)at.getTranslateX() + y);
            lineDataInfo.x2 = lineDataInfo.x1 + Math.round(width - x);
            break;
        }
        dataStream.createLine(lineDataInfo);
    }
}