aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/sl/usermodel/PaintStyle.java
blob: 52bcec71463af307212ed6f1f1ce74ac74f07c56 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* ====================================================================
   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.
==================================================================== */

package org.apache.poi.sl.usermodel;

import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.io.InputStream;



public interface PaintStyle {
    /**
     * The PaintStyle can be modified by secondary sources, e.g. the attributes in the preset shapes.
     * These modifications need to be taken into account when the final color is determined.
     */
    enum PaintModifier {
        /** don't use any paint/fill */
        NONE,
        /** use the paint/filling as-is */
        NORM,
        /** lighten the paint/filling */
        LIGHTEN,
        /** lighten (... a bit less) the paint/filling */
        LIGHTEN_LESS,
        /** darken the paint/filling */
        DARKEN,
        /** darken (... a bit less) the paint/filling */
        DARKEN_LESS
    }

    enum FlipMode {
        /** not flipped/mirrored */
        NONE,
        /** flipped/mirrored/duplicated along the x axis */
        X,
        /** flipped/mirrored/duplicated along the y axis */
        Y,
        /** flipped/mirrored/duplicated along the x and y axis */
        XY
    }

    enum TextureAlignment {
        BOTTOM("b"),
        BOTTOM_LEFT("bl"),
        BOTTOM_RIGHT("br"),
        CENTER("ctr"),
        LEFT("l"),
        RIGHT("r"),
        TOP("t"),
        TOP_LEFT("tl"),
        TOP_RIGHT("tr");

        private final String ooxmlId;

        TextureAlignment(String ooxmlId) {
            this.ooxmlId = ooxmlId;
        }

        public static TextureAlignment fromOoxmlId(String ooxmlId) {
            for (TextureAlignment ta : values()) {
                if (ta.ooxmlId.equals(ooxmlId)) {
                    return ta;
                }
            }
            return null;
        }
    }


    interface SolidPaint extends PaintStyle {
        ColorStyle getSolidColor();
    }

    interface GradientPaint extends PaintStyle {
        enum GradientType { linear, circular, shape }
        
        /**
         * @return the angle of the gradient
         */
        double getGradientAngle();
        ColorStyle[] getGradientColors();
        float[] getGradientFractions();
        boolean isRotatedWithShape();
        GradientType getGradientType();
    }    
    
    interface TexturePaint extends PaintStyle {
        /**
         * @return the raw image stream
         */
        InputStream getImageData();

        /**
         * @return the content type of the image data
         */
        String getContentType();
        
        /**
         * @return the alpha mask in percents [0..100000]
         */
        int getAlpha();

        /**
         * @return {@code true}, if the rotation of the shape is also applied to the texture paint
         */
        default boolean isRotatedWithShape() { return true; }

        /**
         * @return the dimensions of the tiles in percent of the shape dimensions
         * or {@code null} if no scaling is applied
         */
        default Dimension2D getScale() { return null; }

        /**
         * @return the offset of the tiles in points or {@code null} if there's no offset
         */
        default Point2D getOffset() { return null; }

        /**
         * @return the flip/mirroring/duplication mode
         */
        default FlipMode getFlipMode() { return FlipMode.NONE; }


        default TextureAlignment getAlignment() { return null; }
    }
}