File: MfLogBrush.java

package info (click to toggle)
libpixie-java 1%3A1.1.6-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,076 kB
  • sloc: java: 10,175; xml: 1,579; makefile: 13
file content (308 lines) | stat: -rw-r--r-- 9,117 bytes parent folder | download | duplicates (3)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
 * This program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 * or from the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * Copyright (c) 2000 - 2009 Pentaho Corporation, Object Refinery Limited and Contributors.  All rights reserved.
 */

package org.pentaho.reporting.libraries.pixie.wmf;

import java.awt.Color;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;

/**
 * A Windows metafile logical brush object.
 */
public class MfLogBrush implements WmfObject
{
  private static final boolean WHITE = false;
  private static final boolean BLACK = true;

  private static final boolean[] IMG_HS_HORIZONTAL =
      {
          WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
          BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK,
          BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK,
          WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
      };

  private static final boolean[] IMG_HS_VERTICAL =
      {
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
      };

  private static final boolean[] IMG_HS_FDIAGONAL =
      {
          BLACK, BLACK, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
          WHITE, BLACK, BLACK, WHITE, WHITE, WHITE, WHITE, WHITE,
          WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE,
          WHITE, WHITE, WHITE, WHITE, WHITE, BLACK, BLACK, WHITE,
          WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, BLACK, BLACK,
          BLACK, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, BLACK,
      };

  private static final boolean[] IMG_HS_BDIAGONAL =
      {
          BLACK, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, BLACK,
          WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, BLACK, BLACK,
          WHITE, WHITE, WHITE, WHITE, WHITE, BLACK, BLACK, WHITE,
          WHITE, WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE, WHITE,
          WHITE, BLACK, BLACK, WHITE, WHITE, WHITE, WHITE, WHITE,
          BLACK, BLACK, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE,
      };

  private static final boolean[] IMG_HS_CROSS =
      {
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK,
          BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK, BLACK,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
      };

  private static final boolean[] IMG_HS_DIAGCROSS =
      {
          BLACK, BLACK, WHITE, WHITE, WHITE, WHITE, BLACK, BLACK,
          WHITE, BLACK, BLACK, WHITE, WHITE, BLACK, BLACK, WHITE,
          WHITE, WHITE, BLACK, BLACK, BLACK, BLACK, WHITE, WHITE,
          WHITE, WHITE, WHITE, BLACK, BLACK, WHITE, WHITE, WHITE,
          WHITE, WHITE, BLACK, BLACK, BLACK, BLACK, WHITE, WHITE,
          WHITE, BLACK, BLACK, WHITE, WHITE, BLACK, BLACK, WHITE,
          BLACK, BLACK, WHITE, WHITE, WHITE, WHITE, BLACK, BLACK,
          BLACK, WHITE, WHITE, WHITE, WHITE, WHITE, WHITE, BLACK,
      };

  public static final int COLOR_FULL_ALPHA = 0x00FFFFFF;

  // Brush styles.
  public static final int BS_SOLID = 0;
  public static final int BS_NULL = 1;
  public static final int BS_HATCHED = 2;
  public static final int BS_PATTERN = 3;
  public static final int BS_INDEXED = 4;
  public static final int BS_DIBPATTERN = 5;

  // Hatch styles.
  public static final int HS_HORIZONTAL = 0;
  public static final int HS_VERTICAL = 1;
  public static final int HS_FDIAGONAL = 2;
  public static final int HS_BDIAGONAL = 3;
  public static final int HS_CROSS = 4;
  public static final int HS_DIAGCROSS = 5;

  private int style;
  private Color color;
  private Color bgColor;
  private int hatch;
  private Paint lastPaint;
  private BufferedImage bitmap;

  /**
   * The default brush for a new DC.
   */
  public MfLogBrush()
  {
    style = BS_SOLID;
    color = Color.white;
    bgColor = new Color(COLOR_FULL_ALPHA);
    hatch = HS_HORIZONTAL;

  }

  public boolean isVisible()
  {
    return getStyle() != BS_NULL;
  }

  public int getType()
  {
    return OBJ_BRUSH;
  }

  /**
   * The style of this brush.
   */
  public int getStyle()
  {
    return style;
  }

  public void setStyle(final int style)
  {
    this.style = style;
  }

  /**
   * Return the color of the current brush, or null.
   */
  public Color getColor()
  {
    return color;
  }

  public void setColor(final Color color)
  {
    this.color = color;
    lastPaint = null;
  }

  /**
   * The hatch style of this brush.
   */
  public int getHatchedStyle()
  {
    return hatch;
  }

  public void setHatchedStyle(final int hstyle)
  {
    this.hatch = hstyle;
    lastPaint = null;
  }

  public Paint getPaint()
  {
    if (lastPaint != null)
    {
      return lastPaint;
    }

    switch (getStyle())
    {
      case BS_SOLID:
        lastPaint = getColor();
        break;
      case BS_NULL:
        lastPaint = new GDIColor(COLOR_FULL_ALPHA);
        break;
      case BS_HATCHED:
      {
        final BufferedImage image = createHatchStyle();
        lastPaint = new TexturePaint(image, new Rectangle(0, 0, image.getWidth(), image.getHeight()));
        break;
      }
      case BS_DIBPATTERN:
      {
        if (bitmap == null)
        {
          lastPaint = new GDIColor(COLOR_FULL_ALPHA);
        }
        else
        {
          lastPaint = new TexturePaint(bitmap, new Rectangle(0, 0, bitmap.getWidth(), bitmap.getHeight()));
        }
        break;
      }
      default:
      {
        // Unknown Paint Mode
        lastPaint = new GDIColor(COLOR_FULL_ALPHA);
      }
    }
    return lastPaint;
  }

  private BufferedImage createHatchStyle()
  {
    final int style = getHatchedStyle();

    final BufferedImage image = new BufferedImage(8, 8, BufferedImage.TYPE_INT_ARGB);
    switch (style)
    {
      case HS_HORIZONTAL:
        image.setRGB(0, 0, 8, 8, transform(IMG_HS_HORIZONTAL), 0, 8);
        break;
      case HS_VERTICAL:
        image.setRGB(0, 0, 8, 8, transform(IMG_HS_VERTICAL), 0, 8);
        break;
      case HS_FDIAGONAL:
        image.setRGB(0, 0, 8, 8, transform(IMG_HS_FDIAGONAL), 0, 8);
        break;
      case HS_BDIAGONAL:
        image.setRGB(0, 0, 8, 8, transform(IMG_HS_BDIAGONAL), 0, 8);
        break;
      case HS_CROSS:
        image.setRGB(0, 0, 8, 8, transform(IMG_HS_CROSS), 0, 8);
        break;
      case HS_DIAGCROSS:
        image.setRGB(0, 0, 8, 8, transform(IMG_HS_DIAGCROSS), 0, 8);
        break;
      default:
        throw new IllegalArgumentException();
    }
    return image;
  }

  public int[] transform(final boolean[] data)
  {
    final int color = getColor().getRGB();
    final int bgColor = getBackgroundColor().getRGB();

    final int[] retval = new int[data.length];
    for (int i = 0; i < retval.length; i++)
    {
      if (data[i] == true)
      {
        retval[i] = color;
      }
      else
      {
        retval[i] = bgColor;
      }
    }
    return retval;
  }

  public void setBackgroundColor(final Color bg)
  {
    this.bgColor = bg;
    lastPaint = null;
  }

  public Color getBackgroundColor()
  {
    return bgColor;
  }

  public void setBitmap(final BufferedImage bitmap)
  {
    this.bitmap = bitmap;
  }


  public BufferedImage getBitmap()
  {
    return bitmap;
  }
}