svdfmtf.cxx (8718d260) svdfmtf.cxx (9f63b866)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 58 unchanged lines hidden (view full) ---

67#include <basegfx/matrix/b2dhommatrix.hxx>
68#include <basegfx/matrix/b2dhommatrixtools.hxx>
69#include <svx/xlinjoit.hxx>
70#include <svx/xlndsit.hxx>
71#include <basegfx/polygon/b2dpolygonclipper.hxx>
72#include <svx/xbtmpit.hxx>
73#include <svx/xfltrit.hxx>
74#include <vcl/bmpacc.hxx>
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 58 unchanged lines hidden (view full) ---

67#include <basegfx/matrix/b2dhommatrix.hxx>
68#include <basegfx/matrix/b2dhommatrixtools.hxx>
69#include <svx/xlinjoit.hxx>
70#include <svx/xlndsit.hxx>
71#include <basegfx/polygon/b2dpolygonclipper.hxx>
72#include <svx/xbtmpit.hxx>
73#include <svx/xfltrit.hxx>
74#include <vcl/bmpacc.hxx>
75#include <vcl/svgdata.hxx>
76#include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
75#include <svx/xflbmtit.hxx>
76#include <svx/xflbstit.hxx>
77#include <svx/svdpntv.hxx>
77
78////////////////////////////////////////////////////////////////////////////////////////////////////
79
80ImpSdrGDIMetaFileImport::ImpSdrGDIMetaFileImport(
81 SdrModel& rModel,
82 SdrLayerID nLay,
83 const Rectangle& rRect)
84: maTmpList(),

--- 431 unchanged lines hidden (view full) ---

516
517 const BitmapEx aClippedBitmap(
518 aBitmapEx,
519 Point(floor(std::max(0.0, aPixel.getMinX())), floor(std::max(0.0, aPixel.getMinY()))),
520 Size(ceil(aPixel.getWidth()), ceil(aPixel.getHeight())));
521
522 pObj->SetMergedItem(XFillStyleItem(XFILL_BITMAP));
523 pObj->SetMergedItem(XFillBitmapItem(String(), Graphic(aClippedBitmap)));
78
79////////////////////////////////////////////////////////////////////////////////////////////////////
80
81ImpSdrGDIMetaFileImport::ImpSdrGDIMetaFileImport(
82 SdrModel& rModel,
83 SdrLayerID nLay,
84 const Rectangle& rRect)
85: maTmpList(),

--- 431 unchanged lines hidden (view full) ---

517
518 const BitmapEx aClippedBitmap(
519 aBitmapEx,
520 Point(floor(std::max(0.0, aPixel.getMinX())), floor(std::max(0.0, aPixel.getMinY()))),
521 Size(ceil(aPixel.getWidth()), ceil(aPixel.getHeight())));
522
523 pObj->SetMergedItem(XFillStyleItem(XFILL_BITMAP));
524 pObj->SetMergedItem(XFillBitmapItem(String(), Graphic(aClippedBitmap)));
525 pObj->SetMergedItem(XFillBmpTileItem(false));
526 pObj->SetMergedItem(XFillBmpStretchItem(true));
524 }
525 }
526 }
527 }
528
529 if(pObj)
530 {
531 // #i111954# check object for visibility

--- 876 unchanged lines hidden (view full) ---

1408}
1409
1410void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction& rAct)
1411{
1412 const GDIMetaFile& rMtf = rAct.GetGDIMetaFile();
1413
1414 if(rMtf.GetActionCount())
1415 {
527 }
528 }
529 }
530 }
531
532 if(pObj)
533 {
534 // #i111954# check object for visibility

--- 876 unchanged lines hidden (view full) ---

1411}
1412
1413void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction& rAct)
1414{
1415 const GDIMetaFile& rMtf = rAct.GetGDIMetaFile();
1416
1417 if(rMtf.GetActionCount())
1418 {
1416 Rectangle aRect(rAct.GetPoint(),rAct.GetSize());
1417 aRect.Right()++; aRect.Bottom()++;
1419 const Rectangle aRect(rAct.GetPoint(),rAct.GetSize());
1418
1420
1419 // get metafile content as bitmap
1420 const basegfx::B2DRange aTargetRange(
1421 aRect.Left(), aRect.Top(), aRect.Right(), aRect.Bottom());
1422 const drawinglayer::primitive2d::Primitive2DReference aMtf(
1423 new drawinglayer::primitive2d::MetafilePrimitive2D(
1424 basegfx::tools::createScaleTranslateB2DHomMatrix(
1425 aTargetRange.getRange(),
1426 aTargetRange.getMinimum()),
1427 rMtf));
1428 BitmapEx aBitmapEx(convertPrimitive2DSequenceToBitmapEx(
1429 drawinglayer::primitive2d::Primitive2DSequence(&aMtf, 1),
1430 aTargetRange));
1421 // convert metafile sub-content to BitmapEx
1422 BitmapEx aBitmapEx(
1423 convertMetafileToBitmapEx(
1424 rMtf,
1425 basegfx::B2DRange(
1426 aRect.Left(), aRect.Top(),
1427 aRect.Right(), aRect.Bottom()),
1428 125000));
1431
1432 // handle colors
1433 const Gradient& rGradient = rAct.GetGradient();
1434 basegfx::BColor aStart(rGradient.GetStartColor().getBColor());
1435 basegfx::BColor aEnd(rGradient.GetEndColor().getBColor());
1436
1437 if(100 != rGradient.GetStartIntensity())
1438 {

--- 5 unchanged lines hidden (view full) ---

1444 aEnd *= (double)rGradient.GetEndIntensity() / 100.0;
1445 }
1446
1447 const bool bEqualColors(aStart == aEnd);
1448 const bool bNoSteps(1 == rGradient.GetSteps());
1449 bool bCreateObject(true);
1450 bool bHasNewMask(false);
1451 AlphaMask aNewMask;
1429
1430 // handle colors
1431 const Gradient& rGradient = rAct.GetGradient();
1432 basegfx::BColor aStart(rGradient.GetStartColor().getBColor());
1433 basegfx::BColor aEnd(rGradient.GetEndColor().getBColor());
1434
1435 if(100 != rGradient.GetStartIntensity())
1436 {

--- 5 unchanged lines hidden (view full) ---

1442 aEnd *= (double)rGradient.GetEndIntensity() / 100.0;
1443 }
1444
1445 const bool bEqualColors(aStart == aEnd);
1446 const bool bNoSteps(1 == rGradient.GetSteps());
1447 bool bCreateObject(true);
1448 bool bHasNewMask(false);
1449 AlphaMask aNewMask;
1450 double fTransparence(0.0);
1451 bool bFixedTransparence(false);
1452
1453 if(bEqualColors || bNoSteps)
1454 {
1455 // single transparence
1456 const basegfx::BColor aMedium(basegfx::average(aStart, aEnd));
1452
1453 if(bEqualColors || bNoSteps)
1454 {
1455 // single transparence
1456 const basegfx::BColor aMedium(basegfx::average(aStart, aEnd));
1457 const double fTransparence(aMedium.luminance());
1457 fTransparence = aMedium.luminance();
1458
1459 if(basegfx::fTools::lessOrEqual(fTransparence, 0.0))
1460 {
1461 // no transparence needed, all done
1462 }
1463 else if(basegfx::fTools::moreOrEqual(fTransparence, 1.0))
1464 {
1465 // all transparent, no object
1466 bCreateObject = false;
1467 }
1468 else
1469 {
1458
1459 if(basegfx::fTools::lessOrEqual(fTransparence, 0.0))
1460 {
1461 // no transparence needed, all done
1462 }
1463 else if(basegfx::fTools::moreOrEqual(fTransparence, 1.0))
1464 {
1465 // all transparent, no object
1466 bCreateObject = false;
1467 }
1468 else
1469 {
1470 // 0.0 < transparence < 1.0, apply
1471 sal_uInt8 aAlpha(basegfx::fround(fTransparence * 255.0));
1472
1473 aNewMask = AlphaMask(aBitmapEx.GetBitmap().GetSizePixel(), &aAlpha);
1474 bHasNewMask = true;
1470 // 0.0 < transparence < 1.0, apply fixed transparence
1471 bFixedTransparence = true;
1475 }
1476 }
1477 else
1478 {
1479 // gradient transparence
1480 VirtualDevice aVDev;
1481
1482 aVDev.SetOutputSizePixel(aBitmapEx.GetBitmap().GetSizePixel());
1483 aVDev.DrawGradient(Rectangle(Point(0, 0), aVDev.GetOutputSizePixel()), rGradient);
1484
1485 aNewMask = AlphaMask(aVDev.GetBitmap(Point(0, 0), aVDev.GetOutputSizePixel()));
1486 bHasNewMask = true;
1487 }
1488
1489 if(bCreateObject)
1490 {
1472 }
1473 }
1474 else
1475 {
1476 // gradient transparence
1477 VirtualDevice aVDev;
1478
1479 aVDev.SetOutputSizePixel(aBitmapEx.GetBitmap().GetSizePixel());
1480 aVDev.DrawGradient(Rectangle(Point(0, 0), aVDev.GetOutputSizePixel()), rGradient);
1481
1482 aNewMask = AlphaMask(aVDev.GetBitmap(Point(0, 0), aVDev.GetOutputSizePixel()));
1483 bHasNewMask = true;
1484 }
1485
1486 if(bCreateObject)
1487 {
1491 if(bHasNewMask)
1488 if(bHasNewMask || bFixedTransparence)
1492 {
1493 if(!aBitmapEx.IsAlpha() && !aBitmapEx.IsTransparent())
1494 {
1495 // no transparence yet, apply new one
1489 {
1490 if(!aBitmapEx.IsAlpha() && !aBitmapEx.IsTransparent())
1491 {
1492 // no transparence yet, apply new one
1493 if(bFixedTransparence)
1494 {
1495 sal_uInt8 aAlpha(basegfx::fround(fTransparence * 255.0));
1496
1497 aNewMask = AlphaMask(aBitmapEx.GetBitmap().GetSizePixel(), &aAlpha);
1498 }
1499
1496 aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aNewMask);
1497 }
1498 else
1499 {
1500 // mix existing and new alpha mask
1501 AlphaMask aOldMask;
1502
1503 if(aBitmapEx.IsAlpha())

--- 4 unchanged lines hidden (view full) ---

1508 {
1509 aOldMask = aBitmapEx.GetMask();
1510 }
1511 else if(TRANSPARENT_COLOR == aBitmapEx.GetTransparentType())
1512 {
1513 aOldMask = aBitmapEx.GetBitmap().CreateMask(aBitmapEx.GetTransparentColor());
1514 }
1515
1500 aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aNewMask);
1501 }
1502 else
1503 {
1504 // mix existing and new alpha mask
1505 AlphaMask aOldMask;
1506
1507 if(aBitmapEx.IsAlpha())

--- 4 unchanged lines hidden (view full) ---

1512 {
1513 aOldMask = aBitmapEx.GetMask();
1514 }
1515 else if(TRANSPARENT_COLOR == aBitmapEx.GetTransparentType())
1516 {
1517 aOldMask = aBitmapEx.GetBitmap().CreateMask(aBitmapEx.GetTransparentColor());
1518 }
1519
1516 BitmapReadAccess* pOld = aOldMask.AcquireReadAccess();
1517 BitmapWriteAccess* pNew = aNewMask.AcquireWriteAccess();
1520 BitmapWriteAccess* pOld = aOldMask.AcquireWriteAccess();
1518
1521
1519 if(pOld && pNew)
1522 if(pOld)
1520 {
1523 {
1521 if(pOld->Width() == pNew->Width() && pOld->Height() == pNew->Height())
1524 const double fFactor(1.0 / 255.0);
1525
1526 if(bFixedTransparence)
1522 {
1527 {
1523 for(sal_uInt32 y(0); y < pNew->Height(); y++)
1528 const double fOpNew(1.0 - fTransparence);
1529
1530 for(sal_uInt32 y(0); y < pOld->Height(); y++)
1524 {
1531 {
1525 for(sal_uInt32 x(0); x < pNew->Width(); x++)
1532 for(sal_uInt32 x(0); x < pOld->Width(); x++)
1526 {
1533 {
1527 const BitmapColor aColOld(pOld->GetPixel(y, x));
1528 const BitmapColor aColNew(pNew->GetPixel(y, x));
1529 const sal_uInt16 aCombine(sal_uInt16(aColOld.GetIndex()) + sal_uInt16(aColNew.GetIndex()));
1530
1531 pNew->SetPixel(y, x, BitmapColor(aCombine > 255 ? 255 : sal_uInt8(aCombine)));
1534 const double fOpOld(1.0 - (pOld->GetPixel(y, x).GetIndex() * fFactor));
1535 const sal_uInt8 aCol(basegfx::fround((1.0 - (fOpOld * fOpNew)) * 255.0));
1536
1537 pOld->SetPixel(y, x, BitmapColor(aCol));
1532 }
1533 }
1534 }
1535 else
1536 {
1538 }
1539 }
1540 }
1541 else
1542 {
1537 OSL_ENSURE(false, "Alpha masks have different sizes (!)");
1538 }
1543 BitmapReadAccess* pNew = aNewMask.AcquireReadAccess();
1544
1545 if(pNew)
1546 {
1547 if(pOld->Width() == pNew->Width() && pOld->Height() == pNew->Height())
1548 {
1549 for(sal_uInt32 y(0); y < pOld->Height(); y++)
1550 {
1551 for(sal_uInt32 x(0); x < pOld->Width(); x++)
1552 {
1553 const double fOpOld(1.0 - (pOld->GetPixel(y, x).GetIndex() * fFactor));
1554 const double fOpNew(1.0 - (pNew->GetPixel(y, x).GetIndex() * fFactor));
1555 const sal_uInt8 aCol(basegfx::fround((1.0 - (fOpOld * fOpNew)) * 255.0));
1556
1557 pOld->SetPixel(y, x, BitmapColor(aCol));
1558 }
1559 }
1560 }
1561 else
1562 {
1563 OSL_ENSURE(false, "Alpha masks have different sizes (!)");
1564 }
1539
1565
1566 aNewMask.ReleaseAccess(pNew);
1567 }
1568 else
1569 {
1570 OSL_ENSURE(false, "Got no access to new alpha mask (!)");
1571 }
1572 }
1573
1540 aOldMask.ReleaseAccess(pOld);
1574 aOldMask.ReleaseAccess(pOld);
1541 aNewMask.ReleaseAccess(pNew);
1542 }
1543 else
1544 {
1575 }
1576 else
1577 {
1545 OSL_ENSURE(false, "Got no access to alpha bitmaps (!)");
1578 OSL_ENSURE(false, "Got no access to old alpha mask (!)");
1546 }
1547
1548 // apply combined bitmap as mask
1579 }
1580
1581 // apply combined bitmap as mask
1549 aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aNewMask);
1582 aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aOldMask);
1550 }
1551 }
1552
1553 // create and add object
1554 SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);
1555
1556 InsertObj(pGraf);
1557 }
1558 }
1559}
1560
1561////////////////////////////////////////////////////////////////////////////////////////////////////
1562// eof
1583 }
1584 }
1585
1586 // create and add object
1587 SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);
1588
1589 InsertObj(pGraf);
1590 }
1591 }
1592}
1593
1594////////////////////////////////////////////////////////////////////////////////////////////////////
1595// eof