LibreOffice Module svx (master)  1
paraprev.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sfx2/dialoghelper.hxx>
21 #include <svx/paraprev.hxx>
22 #include <vcl/outdev.hxx>
23 #include <vcl/settings.hxx>
24 
26  nLeftMargin ( 0 ),
27  nRightMargin ( 0 ),
28  nFirstLineOffset ( 0 ),
29  nUpper ( 0 ),
30  nLower ( 0 ),
31  eAdjust ( SvxAdjust::Left ),
32  eLastLine ( SvxAdjust::Left ),
33  eLine ( SvxPrevLineSpace::N1 )
34 {
35  aSize = Size(11905, 16837);
36 }
37 
39 {
40  CustomWidgetController::SetDrawingArea(pDrawingArea);
41  Size aOptimalSize(getParagraphPreviewOptimalSize(pDrawingArea->get_ref_device()));
42  pDrawingArea->set_size_request(aOptimalSize.Width(), aOptimalSize.Height());
43 }
44 
46 {
47  DrawParagraph(rRenderContext);
48 }
49 
50 #define DEF_MARGIN 120
51 
53 {
54  // Count in Twips by default
55  rRenderContext.Push(vcl::PushFlags::MAPMODE);
56  rRenderContext.SetMapMode(MapMode(MapUnit::MapTwip));
57 
58  Size aWinSize(GetOutputSizePixel());
59  aWinSize = rRenderContext.PixelToLogic(aWinSize);
60  Size aTmp(1, 1);
61  aTmp = rRenderContext.PixelToLogic(aTmp);
62  aWinSize.AdjustWidth( -(aTmp.Width() /2) );
63  aWinSize.AdjustHeight( -(aTmp.Height() /2) );
64 
65  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
66  const Color& rWinColor = rStyleSettings.GetWindowColor();
67  Color aGrayColor(COL_LIGHTGRAY);
68 
69  rRenderContext.SetFillColor(rWinColor);
70  rRenderContext.DrawRect(tools::Rectangle(Point(), aWinSize));
71 
72  rRenderContext.SetLineColor();
73 
74  tools::Long nH = aWinSize.Height() / 19;
75  Size aLineSiz(aWinSize.Width() - DEF_MARGIN, nH);
76  Size aSiz = aLineSiz;
77  Point aPnt;
78  aPnt.setX( DEF_MARGIN / 2 );
79  rRenderContext.SetFillColor(aGrayColor);
80 
81  for (sal_uInt16 i = 0; i < 9; ++i)
82  {
83  if (i == 3)
84  {
85  rRenderContext.SetFillColor(COL_GRAY);
86  auto nTop = nUpper * aLineSiz.Height() / aSize.Height();
87  aPnt.AdjustY(nTop * 2 );
88  }
89 
90  if (i == 6 )
91  rRenderContext.SetFillColor(aGrayColor);
92 
93  if (3 <= i && 6 > i)
94  {
95  tools::Long nLeft = nLeftMargin * aLineSiz.Width() / aSize.Width();
96  tools::Long nFirst = nFirstLineOffset * aLineSiz.Width() / aSize.Width();
97  tools::Long nTmp = nLeft + nFirst;
98 
99  if (i == 3)
100  {
101  aPnt.AdjustX(nTmp );
102  aSiz.AdjustWidth( -nTmp );
103  }
104  else
105  {
106  aPnt.AdjustX(nLeft );
107  aSiz.AdjustWidth( -nLeft );
108  }
109  tools::Long nRight = nRightMargin * aLineSiz.Width() / aSize.Width();
110  aSiz.AdjustWidth( -nRight );
111  }
112 
113  if (4 == i || 5 == i || 6 == i)
114  {
115  switch (eLine)
116  {
118  break;
120  aPnt.AdjustY(nH / 6.67 ); // 1/.15 = 6.(6)
121  break;
123  aPnt.AdjustY(nH / 2 );
124  break;
126  aPnt.AdjustY(nH );
127  break;
131  break;
132  }
133  }
134 
135  aPnt.AdjustY(nH );
136 
137  if (3 <= i && 5 >= i)
138  {
139  tools::Long nLW = tools::Long();
140  switch (i)
141  {
142  case 3:
143  nLW = aLineSiz.Width() * 8 / 10;
144  break;
145  case 4:
146  nLW = aLineSiz.Width() * 9 / 10;
147  break;
148  case 5:
149  nLW = aLineSiz.Width() / 2;
150  break;
151  }
152 
153  if (nLW > aSiz.Width())
154  nLW = aSiz.Width();
155 
156  switch (eAdjust)
157  {
158  case SvxAdjust::Left:
159  break;
160  case SvxAdjust::Right:
161  aPnt.AdjustX( aSiz.Width() - nLW );
162  break;
163  case SvxAdjust::Center:
164  aPnt.AdjustX(( aSiz.Width() - nLW ) / 2 );
165  break;
166  default: ; //prevent warning
167  }
168  if (SvxAdjust::Block == eAdjust)
169  {
170  if(5 == i)
171  {
172  switch( eLastLine )
173  {
174  case SvxAdjust::Left:
175  break;
176  case SvxAdjust::Right:
177  aPnt.AdjustX( aSiz.Width() - nLW );
178  break;
179  case SvxAdjust::Center:
180  aPnt.AdjustX(( aSiz.Width() - nLW ) / 2 );
181  break;
182  case SvxAdjust::Block:
183  nLW = aSiz.Width();
184  break;
185  default: ; //prevent warning
186  }
187  }
188  else
189  nLW = aSiz.Width();
190  }
191  aSiz.setWidth( nLW );
192  }
193 
194  tools::Rectangle aRect(aPnt, aSiz);
195 
196  rRenderContext.DrawRect( aRect );
197 
198  if (5 == i)
199  {
200  auto nBottom = nLower * aLineSiz.Height() / aSize.Height();
201  aPnt.AdjustY(nBottom * 2 );
202  }
203 
204  aPnt.AdjustY(nH );
205  // Reset, recalculate for each line
206  aPnt.setX( DEF_MARGIN / 2 );
207  aSiz = aLineSiz;
208  }
209  rRenderContext.Pop();
210 }
211 
212 #undef DEF_MARGIN
213 
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxAdjust eAdjust
Definition: paraprev.hxx:49
tools::Long nLeftMargin
Definition: paraprev.hxx:42
tools::Long const nLeftMargin
long Long
const StyleSettings & GetStyleSettings() const
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
SvxPrevLineSpace
Definition: paraprev.hxx:26
constexpr::Color COL_LIGHTGRAY(0xC0, 0xC0, 0xC0)
sal_Int32 nFirstLineOffset
void DrawParagraph(vcl::RenderContext &rRenderContext)
Definition: paraprev.cxx:52
void SetMapMode()
Size const & GetOutputSizePixel() const
constexpr tools::Long Width() const
Size getParagraphPreviewOptimalSize(const OutputDevice &rReference)
virtual OutputDevice & get_ref_device()=0
void DrawRect(const tools::Rectangle &rRect)
short nFirstLineOffset
Definition: paraprev.hxx:44
void SetLineColor()
sal_uInt16 nLower
Definition: paraprev.hxx:47
SvxAdjust
int i
sal_uInt16 nUpper
Definition: paraprev.hxx:46
SvxAdjust eLastLine
Definition: paraprev.hxx:51
tools::Long nRightMargin
Definition: paraprev.hxx:43
void SetFillColor()
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_GRAY
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: paraprev.cxx:45
const AllSettings & GetSettings() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SvxPrevLineSpace eLine
Definition: paraprev.hxx:53
constexpr tools::Long Height() const
tools::Long AdjustWidth(tools::Long n)
const Color & GetWindowColor() const
tools::Long const nRightMargin
#define DEF_MARGIN
Definition: paraprev.cxx:50
tools::Long AdjustHeight(tools::Long n)
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: paraprev.cxx:38
Left
virtual void set_size_request(int nWidth, int nHeight)=0