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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
|
/*
* 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.Graphics2D;
import java.awt.Rectangle;
/**
* Track the state of the DeviceContext of a Windows metafile.
*/
public class MfDcState implements Cloneable
{
public static class MfScale
{
private int yNum;
private int xNum;
private int yDenom;
private int xDenom;
public MfScale(final int xNum, final int xDenom, final int yNum, final int yDenom)
{
if (xNum == 0 || yNum == 0 || xDenom == 0 || yDenom == 0)
{
throw new IllegalArgumentException("Illegal Scaling");
}
this.xNum = xNum;
this.yNum = yNum;
this.xDenom = xDenom;
this.yDenom = yDenom;
}
public int scaleX(final int coord)
{
return ((coord * xNum) / xDenom);
}
public int scaleY(final int coord)
{
return ((coord * yNum) / yDenom);
}
}
private int viewportOrgX;
private int viewportOrgY;
private int viewportExtX = 1;
private int viewportExtY = 1;
private int windowExtX = 1;
private int windowExtY = 1;
private MfScale viewportScale;
private MfScale windowScale;
private int curPosX;
private int curPosY;
private Color fgColor;
private Color bkColor;
private Color textColor;
private int textAlign;
private int textCharExtra;
private int breakCount;
private int extraSpaceLength;
private int bkmode;
private MfLogBrush logBrush;
private MfLogPen logPen;
private MfLogFont logFont;
private MfLogRegion logRegion;
private MfLogPalette logPalette;
private int polyFillMode;
private int rop;
private int mapMode;
private int mapperFlag;
private int stretchBltMode;
private Rectangle clipRegion;
private WmfFile parent;
public MfDcState(final WmfFile parent)
{
fgColor = Color.black;
bkColor = Color.white;
textColor = Color.black;
this.logBrush = new MfLogBrush();
this.logPen = new MfLogPen();
this.parent = parent;
}
public MfDcState(final MfDcState copy)
{
this.parent = copy.parent;
this.windowExtX = copy.windowExtX;
this.windowExtY = copy.windowExtY;
this.viewportOrgX = copy.viewportOrgX;
this.viewportOrgY = copy.viewportOrgY;
this.viewportExtX = copy.viewportExtX;
this.viewportExtY = copy.viewportExtY;
this.curPosX = copy.curPosX;
this.curPosY = copy.curPosY;
this.fgColor = copy.fgColor;
this.bkColor = copy.bkColor;
this.textAlign = copy.textAlign;
this.textCharExtra = copy.textCharExtra;
this.textColor = copy.textColor;
this.logBrush = copy.logBrush;
this.logPen = copy.logPen;
this.logFont = copy.logFont;
this.mapMode = copy.mapMode;
this.mapperFlag = copy.mapperFlag;
this.stretchBltMode = copy.stretchBltMode;
this.viewportScale = copy.viewportScale;
this.windowScale = copy.windowScale;
this.polyFillMode = copy.polyFillMode;
this.rop = copy.rop;
this.bkmode = copy.bkmode;
this.breakCount = copy.breakCount;
this.extraSpaceLength = copy.extraSpaceLength;
if (copy.clipRegion != null)
{
this.clipRegion = new Rectangle(copy.clipRegion);
}
}
public void restoredState()
{
final Graphics2D graphic = parent.getGraphics2D();
if (logBrush != null)
{
updateBrushBackground();
graphic.setPaint(logBrush.getPaint());
}
if (logPen != null)
{
graphic.setStroke(logPen.getStroke());
}
if (logFont != null)
{
graphic.setFont(logFont.createFont());
}
}
// if no clipping region is set and the default clipping region
// is not modified, return the current viewport
//
// btw. i dont have a clue, whether this is the correct implementation :)
public Rectangle getClipRegion()
{
if (clipRegion == null)
{
return new Rectangle(viewportOrgX, viewportOrgY, viewportExtX, viewportExtY);
}
return clipRegion;
}
public void setClipRegion(final Rectangle clipRegion)
{
this.clipRegion = clipRegion;
}
public int getBkMode()
{
return bkmode;
}
public void setBkMode(final int bkmode)
{
if (this.bkmode != bkmode)
{
this.bkmode = bkmode;
updateBrushBackground();
}
}
private void updateBrushBackground()
{
if (bkmode == BrushConstants.TRANSPARENT)
{
logBrush.setBackgroundColor(new Color(MfLogBrush.COLOR_FULL_ALPHA, true));
}
else
{
logBrush.setBackgroundColor(getBkColor());
}
}
public int getBreakCount()
{
return breakCount;
}
public int getExtraSpaceLength()
{
return extraSpaceLength;
}
public void setTextJustification(final int breakCount, final int extraSpaceLength)
{
this.breakCount = breakCount;
this.extraSpaceLength = extraSpaceLength;
}
public int getStretchBltMode()
{
return stretchBltMode;
}
public void setStretchBltMode(final int stretchBltMode)
{
this.stretchBltMode = stretchBltMode;
}
public Color getTextColor()
{
return textColor;
}
public void setTextColor(final Color textColor)
{
this.textColor = textColor;
}
public int getTextCharExtra()
{
return textCharExtra;
}
public void setTextCharExtra(final int textCharExtra)
{
this.textCharExtra = textCharExtra;
}
public int getMapMode()
{
return mapMode;
}
public void setMapMode(final int mapMode)
{
this.mapMode = mapMode;
}
public int getMapperFlag()
{
return mapperFlag;
}
public void setMapperFlag(final int mapperFlag)
{
this.mapperFlag = mapperFlag;
}
public int getROP()
{
return rop;
}
public void setROP(final int rop)
{
this.rop = rop;
}
public int getPolyFillMode()
{
return polyFillMode;
}
public void setPolyFillMode(final int mode)
{
this.polyFillMode = mode;
}
public void setWindowOrg(final int windowOrgX, final int windowOrgY)
{
this.viewportOrgY = -windowOrgY;
this.viewportOrgX = -windowOrgX;
}
public int getWindowOrgX()
{
return viewportOrgX;
}
public int getWindowOrgY()
{
return viewportOrgY;
}
public void setWindowExt(final int windowExtX, final int windowExtY)
{
this.windowExtY = windowExtY;
this.windowExtX = windowExtX;
}
public int getWindowExtX()
{
return windowExtX;
}
public int getWindowExtY()
{
return windowExtY;
}
public void setViewportOrg(final int viewportOrgX, final int viewportOrgY)
{
this.viewportOrgX = viewportOrgX;
this.viewportOrgY = viewportOrgY;
}
public int getViewportOrgX()
{
return viewportOrgX;
}
public int getViewportOrgY()
{
return viewportOrgY;
}
public void setViewportExt(final int viewportExtX, final int viewportExtY)
{
this.viewportExtY = viewportExtY;
this.viewportExtX = viewportExtX;
}
public int getViewportExtX()
{
return viewportExtX;
}
public int getViewportExtY()
{
return viewportExtY;
}
public void setCurPos(final int _curPosX, final int _curPosY)
{
this.curPosY = _curPosY;
this.curPosX = _curPosX;
}
public int getCurPosX()
{
return curPosX;
}
public int getCurPosY()
{
return curPosY;
}
public int getTextAlign()
{
return textAlign;
}
public void setTextAlign(final int textAlign)
{
this.textAlign = textAlign;
}
public void setFgColor(final Color fgColor)
{
if (fgColor == null)
{
throw new NullPointerException();
}
this.fgColor = fgColor;
logBrush.setColor(fgColor);
logPen.setColor(fgColor);
}
public void setBkColor(final Color bkColor)
{
if (bkColor == null)
{
throw new NullPointerException();
}
this.bkColor = bkColor;
logBrush.setBackgroundColor(bkColor);
}
public Color getFgColor()
{
return fgColor;
}
public Color getBkColor()
{
return bkColor;
}
public MfLogFont getLogFont()
{
return logFont;
}
public MfLogBrush getLogBrush()
{
return logBrush;
}
public MfLogPen getLogPen()
{
return logPen;
}
public void setLogFont(final MfLogFont logFont)
{
if (logFont == null)
{
throw new NullPointerException();
}
this.logFont = logFont;
}
public void setLogBrush(final MfLogBrush logBrush)
{
if (logBrush == null)
{
throw new NullPointerException();
}
this.logBrush = logBrush;
updateBrushBackground();
parent.getGraphics2D().setPaint(logBrush.getPaint());
}
public void setLogPen(final MfLogPen logPen)
{
if (logPen == null)
{
throw new NullPointerException();
}
this.logPen = logPen;
parent.getGraphics2D().setStroke(logPen.getStroke());
}
public void setLogPalette(final MfLogPalette logPalette)
{
if (logPalette == null)
{
throw new NullPointerException();
}
this.logPalette = logPalette;
}
public void setLogRegion(final MfLogRegion logRegion)
{
if (logRegion == null)
{
throw new NullPointerException();
}
this.logRegion = logRegion;
}
// No scaling yet?
public int getPhysicalX(final int logPointX)
{
return logPointX + viewportOrgX;
}
// No scaling yet?
public int getPhysicalY(final int logPointY)
{
return logPointY + viewportOrgY;
}
public void prepareDraw()
{
parent.getGraphics2D().setPaint(logPen.getColor());
}
public void postDraw()
{
parent.getGraphics2D().setPaint(logBrush.getPaint());
}
public void prepareDrawText()
{
parent.getGraphics2D().setPaint(textColor);
parent.getGraphics2D().setFont(logFont.createFont());
}
public void postDrawText()
{
parent.getGraphics2D().setPaint(logBrush.getPaint());
}
public void preparePaint()
{
parent.getGraphics2D().setPaint(logBrush.getPaint());
}
public void postPaint()
{
}
public int getVerticalTextAlignment()
{
return (textAlign & TextConstants.TA_CENTER);
}
public int getHorizontalTextAlignment()
{
return (textAlign & TextConstants.TA_BASELINE);
}
public MfLogRegion getLogRegion()
{
return logRegion;
}
public MfLogPalette getLogPalette()
{
return logPalette;
}
public Object clone()
throws CloneNotSupportedException
{
return super.clone();
}
}
|