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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* 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 .
*/
#include "viewcontactoftableobj.hxx"
#include <svx/svdotable.hxx>
#include <com/sun/star/table/XTable.hpp>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <sdr/primitive2d/sdrattributecreator.hxx>
#include <sdr/primitive2d/sdrdecompositiontools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <sdr/attribute/sdrtextattribute.hxx>
#include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
#include <editeng/borderline.hxx>
#include <sdr/attribute/sdrfilltextattribute.hxx>
#include <drawinglayer/primitive2d/BufferedDecompositionPrimitive2D.hxx>
#include <drawinglayer/attribute/sdrlineattribute.hxx>
#include <drawinglayer/attribute/sdrshadowattribute.hxx>
#include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
#include <drawinglayer/primitive2d/structuretagprimitive2d.hxx>
#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
#include <svx/sdr/contact/objectcontact.hxx>
#include <svx/svdpage.hxx>
#include <svx/framelink.hxx>
#include <svx/framelinkarray.hxx>
#include <svx/sdooitm.hxx>
#include <vcl/canvastools.hxx>
#include <o3tl/unit_conversion.hxx>
#include <svx/xfltrit.hxx>
#include <cell.hxx>
#include "tablelayouter.hxx"
using editeng::SvxBorderLine;
using namespace com::sun::star;
namespace drawinglayer::primitive2d
{
namespace {
class SdrCellPrimitive2D : public BufferedDecompositionPrimitive2D
{
private:
basegfx::B2DHomMatrix maTransform;
attribute::SdrFillTextAttribute maSdrFTAttribute;
protected:
// local decomposition.
virtual void create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& aViewInformation) const override;
public:
SdrCellPrimitive2D(
const basegfx::B2DHomMatrix& rTransform,
const attribute::SdrFillTextAttribute& rSdrFTAttribute)
: maTransform(rTransform),
maSdrFTAttribute(rSdrFTAttribute)
{
}
// data access
const basegfx::B2DHomMatrix& getTransform() const { return maTransform; }
const attribute::SdrFillTextAttribute& getSdrFTAttribute() const { return maSdrFTAttribute; }
// compare operator
virtual bool operator==(const BasePrimitive2D& rPrimitive) const override;
// provide unique ID
virtual sal_uInt32 getPrimitive2DID() const override;
};
}
void SdrCellPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*aViewInformation*/) const
{
// prepare unit polygon
const basegfx::B2DPolyPolygon aUnitPolyPolygon(basegfx::utils::createUnitPolygon());
// add fill
if(!getSdrFTAttribute().getFill().isDefault())
{
basegfx::B2DPolyPolygon aTransformed(aUnitPolyPolygon);
aTransformed.transform(getTransform());
rContainer.push_back(
createPolyPolygonFillPrimitive(
aTransformed,
getSdrFTAttribute().getFill(),
getSdrFTAttribute().getFillFloatTransGradient()));
}
else
{
// if no fill create one for HitTest and BoundRect fallback
rContainer.push_back(
createHiddenGeometryPrimitives2D(
true,
aUnitPolyPolygon,
getTransform()));
}
// add text
if(!getSdrFTAttribute().getText().isDefault())
{
rContainer.push_back(
createTextPrimitive(
aUnitPolyPolygon,
getTransform(),
getSdrFTAttribute().getText(),
attribute::SdrLineAttribute(),
true,
false));
}
}
bool SdrCellPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
{
if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
{
const SdrCellPrimitive2D& rCompare = static_cast<const SdrCellPrimitive2D&>(rPrimitive);
return (getTransform() == rCompare.getTransform()
&& getSdrFTAttribute() == rCompare.getSdrFTAttribute());
}
return false;
}
// provide unique ID
sal_uInt32 SdrCellPrimitive2D::getPrimitive2DID() const
{
return PRIMITIVE2D_ID_SDRCELLPRIMITIVE2D;
}
} // end of namespace
namespace sdr::contact
{
namespace {
class ViewObjectContactOfTableObj : public ViewObjectContactOfSdrObj
{
public:
ViewObjectContactOfTableObj(ObjectContact& rObjectContact, ViewContact& rViewContact)
: ViewObjectContactOfSdrObj(rObjectContact, rViewContact)
{
}
protected:
virtual void createPrimitive2DSequence(DisplayInfo const& rDisplayInfo, drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const override;
};
} // namespace
static svx::frame::Style impGetLineStyle(
const sdr::table::TableLayouter& rLayouter,
sal_Int32 nX,
sal_Int32 nY,
bool bHorizontal,
sal_Int32 nColCount,
sal_Int32 nRowCount,
bool bIsRTL)
{
if(nX >= 0 && nX <= nColCount && nY >= 0 && nY <= nRowCount)
{
const SvxBorderLine* pLine = rLayouter.getBorderLine(nX, nY, bHorizontal);
if(pLine)
{
// copy line content
SvxBorderLine aLine(*pLine);
// check for mirroring. This shall always be done when it is
// not a top- or rightmost line
bool bMirror(aLine.isDouble());
if(bMirror)
{
if(bHorizontal)
{
// mirror all bottom lines
bMirror = (0 != nY);
}
else
{
// mirror all left lines
bMirror = (bIsRTL ? 0 != nX : nX != nColCount);
}
}
if(bMirror)
{
aLine.SetMirrorWidths( );
}
constexpr double fTwipsToMM(
o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::mm100));
return svx::frame::Style(&aLine, fTwipsToMM);
}
}
// no success, copy empty line
return svx::frame::Style();
}
static void createPrimitive2DSequenceImpl(
sdr::table::SdrTableObj const& rTableObj,
bool const isTaggedPDF,
drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor)
{
const uno::Reference< css::table::XTable > xTable = rTableObj.getTable();
if(xTable.is())
{
// create primitive representation for table. Cell info goes
// directly to aRetval, Border info to aBorderSequence and added
// later to get the correct overlapping
drawinglayer::primitive2d::Primitive2DContainer aRetval;
drawinglayer::primitive2d::Primitive2DContainer aRetvalForShadow;
const sal_Int32 nRowCount(xTable->getRowCount());
const sal_Int32 nColCount(xTable->getColumnCount());
const sal_Int32 nAllCount(nRowCount * nColCount);
SdrPage const*const pPage(rTableObj.getSdrPageFromSdrObject());
if(nAllCount)
{
const sdr::table::TableLayouter& rTableLayouter(rTableObj.getTableLayouter());
const bool bIsRTL(css::text::WritingMode_RL_TB == rTableObj.GetWritingMode());
sdr::table::CellPos aCellPos;
sdr::table::CellRef xCurrentCell;
basegfx::B2IRectangle aCellArea;
// create range using the model data directly. This is in SdrTextObj::aRect which i will access using
// GetGeoRect() to not trigger any calculations. It's the unrotated geometry.
const basegfx::B2DRange aObjectRange = vcl::unotools::b2DRectangleFromRectangle(rTableObj.GetGeoRect());
// To create the CellBorderPrimitives, use the tooling from svx::frame::Array
// which is capable of creating the needed visualization. Fill it during the
// anyways needed run over the table.
svx::frame::Array aArray;
// initialize CellBorderArray for primitive creation
aArray.Initialize(nColCount, nRowCount);
// create single primitives per cell
for(aCellPos.mnRow = 0; aCellPos.mnRow < nRowCount; aCellPos.mnRow++)
{
drawinglayer::primitive2d::Primitive2DContainer row;
// add RowHeight to CellBorderArray for primitive creation
aArray.SetRowHeight(aCellPos.mnRow, rTableLayouter.getRowHeight(aCellPos.mnRow));
for(aCellPos.mnCol = 0; aCellPos.mnCol < nColCount; aCellPos.mnCol++)
{
drawinglayer::primitive2d::Primitive2DContainer cell;
// add ColWidth to CellBorderArray for primitive creation, only
// needs to be done in the 1st run
if(0 == aCellPos.mnRow)
{
aArray.SetColWidth(aCellPos.mnCol, rTableLayouter.getColumnWidth(aCellPos.mnCol));
}
// access the cell
xCurrentCell.set(dynamic_cast< sdr::table::Cell* >(xTable->getCellByPosition(aCellPos.mnCol, aCellPos.mnRow).get()));
if(xCurrentCell.is())
{
// copy styles for current cell to CellBorderArray for primitive creation
aArray.SetCellStyleLeft(aCellPos.mnCol, aCellPos.mnRow, impGetLineStyle(rTableLayouter, aCellPos.mnCol, aCellPos.mnRow, false, nColCount, nRowCount, bIsRTL));
aArray.SetCellStyleRight(aCellPos.mnCol, aCellPos.mnRow, impGetLineStyle(rTableLayouter, aCellPos.mnCol + 1, aCellPos.mnRow, false, nColCount, nRowCount, bIsRTL));
aArray.SetCellStyleTop(aCellPos.mnCol, aCellPos.mnRow, impGetLineStyle(rTableLayouter, aCellPos.mnCol, aCellPos.mnRow, true, nColCount, nRowCount, bIsRTL));
aArray.SetCellStyleBottom(aCellPos.mnCol, aCellPos.mnRow, impGetLineStyle(rTableLayouter, aCellPos.mnCol, aCellPos.mnRow + 1, true, nColCount, nRowCount, bIsRTL));
// ignore merged cells (all except the top-left of a merged cell)
if(!xCurrentCell->isMerged())
{
// check if we are the top-left of a merged cell
const sal_Int32 nXSpan(xCurrentCell->getColumnSpan());
const sal_Int32 nYSpan(xCurrentCell->getRowSpan());
if(nXSpan > 1 || nYSpan > 1)
{
// if merged, set so at CellBorderArray for primitive creation
aArray.SetMergedRange(aCellPos.mnCol, aCellPos.mnRow, aCellPos.mnCol + nXSpan - 1, aCellPos.mnRow + nYSpan - 1);
}
}
}
if(xCurrentCell.is() && !xCurrentCell->isMerged())
{
if(rTableLayouter.getCellArea(xCurrentCell, aCellPos, aCellArea))
{
// create cell transformation matrix
basegfx::B2DHomMatrix aCellMatrix;
aCellMatrix.set(0, 0, static_cast<double>(aCellArea.getWidth()));
aCellMatrix.set(1, 1, static_cast<double>(aCellArea.getHeight()));
aCellMatrix.set(0, 2, static_cast<double>(aCellArea.getMinX()) + aObjectRange.getMinX());
aCellMatrix.set(1, 2, static_cast<double>(aCellArea.getMinY()) + aObjectRange.getMinY());
// handle cell fillings and text
const SfxItemSet& rCellItemSet = xCurrentCell->GetItemSet();
const sal_uInt32 nTextIndex(nColCount * aCellPos.mnRow + aCellPos.mnCol);
const SdrText* pSdrText = rTableObj.getText(nTextIndex);
drawinglayer::attribute::SdrFillTextAttribute aAttribute;
if(pSdrText)
{
// #i101508# take cell's local text frame distances into account
const sal_Int32 nLeft(xCurrentCell->GetTextLeftDistance());
const sal_Int32 nRight(xCurrentCell->GetTextRightDistance());
const sal_Int32 nUpper(xCurrentCell->GetTextUpperDistance());
const sal_Int32 nLower(xCurrentCell->GetTextLowerDistance());
aAttribute = drawinglayer::primitive2d::createNewSdrFillTextAttribute(
rCellItemSet,
pSdrText,
&nLeft,
&nUpper,
&nRight,
&nLower);
}
else
{
aAttribute = drawinglayer::primitive2d::createNewSdrFillTextAttribute(
rCellItemSet,
pSdrText);
}
// always create cell primitives for BoundRect and HitTest
{
const drawinglayer::primitive2d::Primitive2DReference xCellReference(
new drawinglayer::primitive2d::SdrCellPrimitive2D(
aCellMatrix, aAttribute));
cell.append(xCellReference);
}
// Create cell primitive without text.
aAttribute
= drawinglayer::primitive2d::createNewSdrFillTextAttribute(
rCellItemSet, nullptr);
rtl::Reference pCellReference
= new drawinglayer::primitive2d::SdrCellPrimitive2D(
aCellMatrix, aAttribute);
sal_uInt16 nTransparence(
rCellItemSet.Get(XATTR_FILLTRANSPARENCE).GetValue());
if (nTransparence != 0)
{
pCellReference->setTransparenceForShadow(nTransparence);
}
const drawinglayer::primitive2d::Primitive2DReference
xCellReference(pCellReference);
aRetvalForShadow.append(xCellReference);
}
}
if (isTaggedPDF && pPage)
{
// heuristic: if there's a special formatting on
// first row, assume that it's a header row
auto const eType(
aCellPos.mnRow == 0 && rTableObj.getTableStyleSettings().mbUseFirstRow
? vcl::PDFWriter::TableHeader
: vcl::PDFWriter::TableData);
cell = drawinglayer::primitive2d::Primitive2DContainer {
new drawinglayer::primitive2d::StructureTagPrimitive2D(
eType,
pPage->IsMasterPage(),
false,
std::move(cell)) };
}
row.append(cell);
}
if (isTaggedPDF && pPage)
{
row = drawinglayer::primitive2d::Primitive2DContainer {
new drawinglayer::primitive2d::StructureTagPrimitive2D(
vcl::PDFWriter::TableRow,
pPage->IsMasterPage(),
false,
std::move(row)) };
}
aRetval.append(row);
}
// now create all CellBorderPrimitives
drawinglayer::primitive2d::Primitive2DContainer aCellBorderPrimitives(aArray.CreateB2DPrimitiveArray());
if(!aCellBorderPrimitives.empty())
{
// this is already scaled (due to Table in non-uniform coordinates), so
// first transform removing scale
basegfx::B2DHomMatrix aTransform(
basegfx::utils::createScaleB2DHomMatrix(
1.0 / aObjectRange.getWidth(),
1.0 / aObjectRange.getHeight()));
// If RTL, mirror the whole unified table in X and move right.
// This is much easier than taking this into account for the whole
// index calculations
if(bIsRTL)
{
aTransform.scale(-1.0, 1.0);
aTransform.translate(1.0, 0.0);
}
// create object matrix
const GeoStat& rGeoStat(rTableObj.GetGeoStat());
const double fShearX(-rGeoStat.mfTanShearAngle);
const double fRotate(rGeoStat.nRotationAngle ? toRadians(36000_deg100 - rGeoStat.nRotationAngle) : 0.0);
const basegfx::B2DHomMatrix aObjectMatrix(basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
aObjectRange.getWidth(), aObjectRange.getHeight(), fShearX, fRotate,
aObjectRange.getMinX(), aObjectRange.getMinY()));
// add object matrix to transform. By doing so theoretically
// CellBorders could be also rotated/sheared for the first time ever.
// To completely make that work, the primitives already created in
// aRetval would also have to be based on ObjectMatrix, not only on
// ObjectRange as it currently is.
aTransform *= aObjectMatrix;
// create a transform primitive with this and embed CellBorders
// and append to retval
aRetval.append(
new drawinglayer::primitive2d::TransformPrimitive2D(
aTransform,
drawinglayer::primitive2d::Primitive2DContainer(aCellBorderPrimitives)));
// Borders are always the same for shadow as well.
aRetvalForShadow.append(new drawinglayer::primitive2d::TransformPrimitive2D(
aTransform, std::move(aCellBorderPrimitives)));
}
}
if(!aRetval.empty())
{
// check and create evtl. shadow for created content
const SfxItemSet& rObjectItemSet = rTableObj.GetMergedItemSet();
const drawinglayer::attribute::SdrShadowAttribute aNewShadowAttribute(
drawinglayer::primitive2d::createNewSdrShadowAttribute(rObjectItemSet));
if(!aNewShadowAttribute.isDefault())
{
bool bDirectShadow
= rObjectItemSet.Get(SDRATTR_SHADOW, /*bSrchInParent=*/false)
.GetValue();
if (bDirectShadow)
{
// Shadow as direct formatting: no shadow for text, to be compatible
// with PowerPoint.
basegfx::B2DHomMatrix aMatrix;
aRetval = drawinglayer::primitive2d::createEmbeddedShadowPrimitive(
std::move(aRetval), aNewShadowAttribute, aMatrix, &aRetvalForShadow);
}
else
{
// Shadow as style: shadow for text, to be backwards-compatible.
aRetval = drawinglayer::primitive2d::createEmbeddedShadowPrimitive(
std::move(aRetval), aNewShadowAttribute);
}
}
}
rVisitor.visit(std::move(aRetval));
}
else
{
// take unrotated snap rect (direct model data) for position and size
const basegfx::B2DRange aObjectRange = vcl::unotools::b2DRectangleFromRectangle(rTableObj.GetGeoRect());
// create object matrix
const GeoStat& rGeoStat(rTableObj.GetGeoStat());
const double fShearX(-rGeoStat.mfTanShearAngle);
const double fRotate(rGeoStat.nRotationAngle ? toRadians(36000_deg100 - rGeoStat.nRotationAngle) : 0.0);
const basegfx::B2DHomMatrix aObjectMatrix(basegfx::utils::createScaleShearXRotateTranslateB2DHomMatrix(
aObjectRange.getWidth(), aObjectRange.getHeight(), fShearX, fRotate,
aObjectRange.getMinX(), aObjectRange.getMinY()));
// created an invisible outline for the cases where no visible content exists
const drawinglayer::primitive2d::Primitive2DReference xReference(
drawinglayer::primitive2d::createHiddenGeometryPrimitives2D(
aObjectMatrix));
rVisitor.visit(xReference);
}
}
void ViewObjectContactOfTableObj::createPrimitive2DSequence(
DisplayInfo const& rDisplayInfo,
drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
{
bool const isTaggedPDF(GetObjectContact().isExportTaggedPDF());
if (isTaggedPDF)
{
// this will be unbuffered and contain structure tags
const sdr::table::SdrTableObj& rTableObj =
static_cast<const sdr::table::SdrTableObj&>(*GetViewContact().TryToGetSdrObject());
return createPrimitive2DSequenceImpl(rTableObj, true, rVisitor);
}
else
{
// call it via the base class - this is supposed to be buffered
return sdr::contact::ViewObjectContactOfSdrObj::createPrimitive2DSequence(rDisplayInfo, rVisitor);
}
}
void ViewContactOfTableObj::createViewIndependentPrimitive2DSequence(
drawinglayer::primitive2d::Primitive2DDecompositionVisitor& rVisitor) const
{
const sdr::table::SdrTableObj& rTableObj =
static_cast<const sdr::table::SdrTableObj&>(GetSdrObject());
return createPrimitive2DSequenceImpl(rTableObj, false, rVisitor);
}
ViewObjectContact& ViewContactOfTableObj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
{
return *new ViewObjectContactOfTableObj(rObjectContact, *this);
}
ViewContactOfTableObj::ViewContactOfTableObj(sdr::table::SdrTableObj& rTableObj)
: ViewContactOfSdrObj(rTableObj)
{
}
ViewContactOfTableObj::~ViewContactOfTableObj()
{
}
} // end of namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|