1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <address.hxx>
23 #include <cellvalue.hxx>
24 #include <tools/color.hxx>
25 #include <tools/fract.hxx>
26 #include <tools/gen.hxx>
27 #include <editeng/svxenum.hxx>
28 #include <vcl/outdev.hxx>
29 #include <vcl/pdfwriter.hxx>
30 #include <tools/degree.hxx>
31 #include <o3tl/deleter.hxx>
37 class SpellCheckContext
;
41 struct MisspellRanges
;
43 namespace drawinglayer::processor2d
{ class BaseProcessor2D
; }
45 namespace vcl
{ class Font
; }
52 class ScPageBreakData
;
54 class ScFieldEditEngine
;
57 #define SC_SCENARIO_HSPACE 60
58 #define SC_SCENARIO_VSPACE 50
60 enum ScOutputType
{ OUTTYPE_WINDOW
, OUTTYPE_PRINTER
};
62 class ClearableClipRegion
;
63 typedef std::unique_ptr
<ClearableClipRegion
, o3tl::default_delete
<ClearableClipRegion
>> ClearableClipRegionPtr
;
65 typedef std::map
<SCROW
, sal_Int32
> TableRowIdMap
;
66 typedef std::map
<std::pair
<SCROW
, SCCOL
>, sal_Int32
> TableDataIdMap
;
67 struct ScEnhancedPDFState
69 sal_Int32 m_WorksheetId
= -1;
70 sal_Int32 m_TableId
= -1;
71 TableRowIdMap m_TableRowMap
;
72 TableDataIdMap m_TableDataMap
;
73 ScEnhancedPDFState(){};
76 /// Describes reference mark to be drawn, position & size in TWIPs
77 struct ReferenceMark
{
91 , aColor( COL_AUTO
) {}
93 ReferenceMark( tools::Long aX
,
104 , aColor( rColor
) {}
106 bool Is() const { return ( nWidth
> 0 && nHeight
> 0 ); }
111 friend class ScDrawStringsVars
;
112 friend class ScGridWindow
;
114 struct OutputAreaParam
116 tools::Rectangle maAlignRect
;
117 tools::Rectangle maClipRect
;
118 tools::Long mnColWidth
;
119 tools::Long mnLeftClipLength
; /// length of the string getting cut off on the left.
120 tools::Long mnRightClipLength
; /// length of the string getting cut off on the right.
128 SvxCellHorJustify meHorJustAttr
; ///< alignment attribute
129 SvxCellHorJustify meHorJustContext
; ///< context depending on attribute, content and direction
130 SvxCellHorJustify meHorJustResult
; ///< result for EditEngine
131 SvxCellVerJustify meVerJust
;
132 SvxCellJustifyMethod meHorJustMethod
;
133 SvxCellJustifyMethod meVerJustMethod
;
134 SvxCellOrientation meOrient
;
141 tools::Long mnInitPosX
;
143 bool mbCellIsValue
:1;
144 bool mbAsianVertical
:1;
145 bool mbPixelToLogic
:1;
146 bool mbHyphenatorSet
:1;
147 ScFieldEditEngine
* mpEngine
;
148 ScRefCellValue maCell
;
149 const ScPatternAttr
* mpPattern
;
150 const SfxItemSet
* mpCondSet
;
151 const SfxItemSet
* mpPreviewFontSet
;
152 const ScPatternAttr
* mpOldPattern
;
153 const SfxItemSet
* mpOldCondSet
;
154 const SfxItemSet
* mpOldPreviewFontSet
;
155 RowInfo
* mpThisRowInfo
;
156 const std::vector
<editeng::MisspellRanges
>* mpMisspellRanges
;
158 explicit DrawEditParam(const ScPatternAttr
* pPattern
, const SfxItemSet
* pCondSet
, bool bCellIsValue
);
160 bool readCellContent(const ScDocument
* pDoc
, bool bShowNullValues
, bool bShowFormulas
, bool bSyntaxMode
, bool bUseStyleColor
, bool bForceAutoColor
, bool& rWrapFields
);
161 void setPatternToEngine(bool bUseStyleColor
);
162 void calcMargins(tools::Long
& rTop
, tools::Long
& rLeft
, tools::Long
& rBottom
, tools::Long
& rRight
, double nPPTX
, double nPPTY
) const;
163 void calcPaperSize(Size
& rPaperSize
, const tools::Rectangle
& rAlignRect
, double nPPTX
, double nPPTY
) const;
164 void getEngineSize(ScFieldEditEngine
* pEngine
, tools::Long
& rWidth
, tools::Long
& rHeight
) const;
165 bool hasLineBreak() const;
166 bool isHyperlinkCell() const;
169 * When the text is vertically oriented, the text is either rotated 90
170 * degrees to the right or 90 degrees to the left. Note that this is
171 * different from being vertically stacked.
173 bool isVerticallyOriented() const;
176 * Calculate offset position for vertically oriented (either
177 * top-bottom or bottom-top orientation) text.
179 * @param rLogicStart initial position in pixels. When the call is
180 * finished, this parameter will store the new
183 void calcStartPosForVertical(Point
& rLogicStart
, tools::Long nCellWidth
, tools::Long nEngineWidth
, tools::Long nTopM
, const OutputDevice
* pRefDevice
);
185 void setAlignmentToEngine();
186 bool adjustHorAlignment(ScFieldEditEngine
* pEngine
);
187 void adjustForHyperlinkInPDF(Point aURLStart
, const OutputDevice
* pDev
);
190 VclPtr
<OutputDevice
> mpOriginalTargetDevice
; // 'unpatched' TargetDevice
191 VclPtr
<OutputDevice
> mpDev
; // Device
192 VclPtr
<OutputDevice
> mpRefDevice
; // printer if used for preview
193 VclPtr
<OutputDevice
> pFmtDevice
; // reference for text formatting
194 ScTableInfo
& mrTabInfo
;
195 RowInfo
* pRowInfo
; // Info block
196 SCSIZE nArrCount
; // occupied lines in info block
197 ScDocument
* mpDoc
; // Document
199 tools::Long nScrX
; // Output Startpos. (Pixel)
201 tools::Long nScrW
; // Output size (Pixel)
203 tools::Long nMirrorW
; // Visible output width for mirroring (default: nScrW)
204 SCCOL nX1
; // Start-/End coordinates
205 SCROW nY1
; // ( incl. hidden )
208 SCCOL nVisX1
; // Start-/End coordinates
209 SCROW nVisY1
; // ( visible range )
212 ScOutputType eType
; // Screen/Printer ...
213 double mnPPTX
; // Pixel per Twips
218 ScTabViewShell
* pViewShell
; // for connect from visible plug-ins
220 FmFormView
* pDrawView
; // SdrView to paint to
222 bool bEditMode
; // InPlace edited cell - do not output
226 bool bMetaFile
; // Output to metafile (not pixels!)
228 bool bPagebreakMode
; // Page break preview
229 bool bSolidBackground
; // white instead of transparent
231 bool mbUseStyleColor
;
232 bool mbForceAutoColor
;
234 bool mbSyntaxMode
; // Syntax highlighting
235 std::optional
<Color
> mxValueColor
;
236 std::optional
<Color
> mxTextColor
;
237 std::optional
<Color
> mxFormulaColor
;
241 bool mbShowNullValues
;
243 bool bShowSpellErrors
; // Show spelling errors in EditObjects
248 bool bAnyClipped
; // internal
253 // #i74769# use SdrPaintWindow direct, remember it during BeginDrawLayers/EndDrawLayers
254 SdrPaintWindow
* mpTargetPaintWindow
;
255 const sc::SpellCheckContext
* mpSpellCheckCxt
;
256 std::unique_ptr
<ScFieldEditEngine
> mxOutputEditEngine
;
260 bool GetMergeOrigin( SCCOL nX
, SCROW nY
, SCSIZE nArrY
,
261 SCCOL
& rOverX
, SCROW
& rOverY
, bool bVisRowChanged
);
262 bool IsEmptyCellText( const RowInfo
* pThisRowInfo
, SCCOL nX
, SCROW nY
);
263 void GetVisibleCell( SCCOL nCol
, SCROW nRow
, SCTAB nTab
, ScRefCellValue
& rCell
);
265 bool IsAvailable( SCCOL nX
, SCROW nY
);
267 void GetOutputArea( SCCOL nX
, SCSIZE nArrY
, tools::Long nPosX
, tools::Long nPosY
,
268 SCCOL nCellX
, SCROW nCellY
, tools::Long nNeeded
,
269 const ScPatternAttr
& rPattern
,
270 sal_uInt16 nHorJustify
, bool bCellIsValue
,
271 bool bBreak
, bool bOverwrite
,
272 OutputAreaParam
& rParam
);
274 void ShrinkEditEngine( EditEngine
& rEngine
, const tools::Rectangle
& rAlignRect
,
275 tools::Long nLeftM
, tools::Long nTopM
, tools::Long nRightM
, tools::Long nBottomM
,
276 bool bWidth
, SvxCellOrientation nOrient
, Degree100 nAttrRotate
, bool bPixelToLogic
,
277 tools::Long
& rEngineWidth
, tools::Long
& rEngineHeight
, tools::Long
& rNeededPixel
,
278 bool& rLeftClip
, bool& rRightClip
);
280 void SetSyntaxColor( vcl::Font
* pFont
, const ScRefCellValue
& rCell
);
281 void SetEditSyntaxColor( EditEngine
& rEngine
, const ScRefCellValue
& rCell
);
283 double GetStretch() const;
285 void DrawRotatedFrame(vcl::RenderContext
& rRenderContext
); // pixel
287 std::unique_ptr
<drawinglayer::processor2d::BaseProcessor2D
> CreateProcessor2D( );
289 void DrawEditStandard(DrawEditParam
& rParam
);
290 void DrawEditBottomTop(DrawEditParam
& rParam
);
291 void DrawEditTopBottom(DrawEditParam
& rParam
);
292 void DrawEditStacked(DrawEditParam
& rParam
);
293 void DrawEditAsianVertical(DrawEditParam
& rParam
);
295 void InitOutputEditEngine();
297 void SetClipMarks( OutputAreaParam
&aAreaParam
, ScCellInfo
* pClipMarkCell
,
298 SvxCellHorJustify eOutHorJust
, tools::Long nLayoutSign
);
300 void ShowClipMarks( DrawEditParam
& rParam
, tools::Long nEngineWidth
, const Size
& aCellSize
,
301 bool bMerged
, OutputAreaParam
& aAreaParam
, bool bTop
);
303 ClearableClipRegionPtr
Clip(DrawEditParam
& rParam
, const Size
& aCellSize
, OutputAreaParam
& aAreaParam
,
304 tools::Long nEngineWidth
, bool bWrapFields
, bool bTop
);
306 bool AdjustAreaParamClipRect(OutputAreaParam
& rAreaParam
);
307 tools::Long
SetEngineTextAndGetWidth( DrawEditParam
& rParam
, const OUString
& rSetString
,
308 tools::Long
& rNeededPixel
, tools::Long nAddWidthPixels
);
310 // Check for and set cell rotations at OutputData to have it available
311 // in the svx tooling to render the borders. Moved to private section
312 // and the single call to end of constructor to be sure this always happens
313 void SetCellRotations();
318 * @param nNewScrX: X-Offset in the output device for the table
319 * @param nNewScrY: Y-Offset in the output device for the table
322 ScOutputData( OutputDevice
* pNewDev
, ScOutputType eNewType
,
323 ScTableInfo
& rTabInfo
, ScDocument
* pNewDoc
,
324 SCTAB nNewTab
, tools::Long nNewScrX
, tools::Long nNewScrY
,
325 SCCOL nNewX1
, SCROW nNewY1
, SCCOL nNewX2
, SCROW nNewY2
,
326 double nPixelPerTwipsX
, double nPixelPerTwipsY
,
327 const Fraction
* pZoomX
= nullptr,
328 const Fraction
* pZoomY
= nullptr );
332 void SetSpellCheckContext( const sc::SpellCheckContext
* pCxt
);
333 void SetContentDevice( OutputDevice
* pContentDev
);
335 void SetRefDevice( OutputDevice
* pRDev
);
336 void SetFmtDevice( OutputDevice
* pRDev
);
337 void SetViewShell( ScTabViewShell
* pSh
) { pViewShell
= pSh
; }
339 void SetDrawView( FmFormView
* pNew
) { pDrawView
= pNew
; }
341 void SetSolidBackground( bool bSet
) { bSolidBackground
= bSet
; }
342 void SetUseStyleColor( bool bSet
);
344 void SetEditCell( SCCOL nCol
, SCROW nRow
);
345 void SetSyntaxMode( bool bNewMode
);
346 void SetMetaFileMode( bool bNewMode
);
347 void SetGridColor( const Color
& rColor
);
348 void SetMarkClipped( bool bSet
);
349 void SetShowNullValues ( bool bSet
);
350 void SetShowFormulas ( bool bSet
);
351 void SetShowSpellErrors( bool bSet
);
352 void SetMirrorWidth( tools::Long nNew
);
353 tools::Long
GetScrW() const { return nScrW
; }
354 tools::Long
GetScrH() const { return nScrH
; }
358 bool ReopenPDFStructureElement(vcl::PDFWriter::StructElement aType
, SCROW nRow
= -1,
361 void DrawGrid(vcl::RenderContext
& rRenderContext
, bool bGrid
, bool bPage
, bool bMergeCover
= false);
362 void DrawStrings( bool bPixelToLogic
= false );
365 void LayoutStrings(bool bPixelToLogic
);
367 void DrawDocumentBackground();
368 void DrawBackground(vcl::RenderContext
& rRenderContext
);
370 void DrawExtraShadow(bool bLeft
, bool bTop
, bool bRight
, bool bBottom
);
371 void DrawFrame(vcl::RenderContext
& rRenderContext
);
373 // with logic MapMode set!
374 void DrawEdit(bool bPixelToLogic
);
375 void DrawRotated(bool bPixelToLogic
); // logical
379 // #i72502# printer only command set
380 Point
PrePrintDrawingLayer(tools::Long nLogStX
, tools::Long nLogStY
);
381 void PostPrintDrawingLayer(const Point
& rMMOffset
); // #i74768# need offset for FormLayer
382 void PrintDrawingLayer(SdrLayerID nLayer
, const Point
& rMMOffset
);
385 void DrawSelectiveObjects(SdrLayerID nLayer
);
387 bool SetChangedClip(); // sal_False = not
388 vcl::Region
GetChangedAreaRegion();
391 void SetPagebreakMode( ScPageBreakData
* pPageData
);
392 /// Draws reference mark and returns its properties
393 void DrawRefMark( SCCOL nRefStartX
, SCROW nRefStartY
,
394 SCCOL nRefEndX
, SCROW nRefEndY
,
395 const Color
& rColor
, bool bHandle
);
396 ReferenceMark
FillReferenceMark( SCCOL nRefStartX
, SCROW nRefStartY
,
397 SCCOL nRefEndX
, SCROW nRefEndY
,
398 const Color
& rColor
);
399 void DrawOneChange( SCCOL nRefStartX
, SCROW nRefStartY
,
400 SCCOL nRefEndX
, SCROW nRefEndY
,
401 const Color
& rColor
, sal_uInt16 nType
);
402 void DrawChangeTrack();
403 void DrawClipMarks();
405 void DrawNoteMarks(vcl::RenderContext
& rRenderContext
);
406 void DrawFormulaMarks(vcl::RenderContext
& rRenderContext
);
408 void DrawSparklines(vcl::RenderContext
& rRenderContext
);
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */