LibreOffice Module sdext (master)  1
writertreevisiting.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 
21 #include <pdfiprocessor.hxx>
22 #include <xmlemitter.hxx>
23 #include <pdfihelper.hxx>
24 #include <imagecontainer.hxx>
25 #include "style.hxx"
26 #include "writertreevisiting.hxx"
27 #include <genericelements.hxx>
28 
30 #include <osl/diagnose.h>
31 
32 using namespace ::com::sun::star;
33 
34 namespace pdfi
35 {
36 
37 void WriterXmlEmitter::visit( HyperlinkElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
38 {
39  if( elem.Children.empty() )
40  return;
41 
42  const char* pType = dynamic_cast<DrawElement*>(elem.Children.front().get()) ? "draw:a" : "text:a";
43 
44  PropertyMap aProps;
45  aProps[ "xlink:type" ] = "simple";
46  aProps[ "xlink:href" ] = elem.URI;
47  aProps[ "office:target-frame-name" ] = "_blank";
48  aProps[ "xlink:show" ] = "new";
49 
50  m_rEmitContext.rEmitter.beginTag( pType, aProps );
51  auto this_it = elem.Children.begin();
52  while( this_it != elem.Children.end() && this_it->get() != &elem )
53  {
54  (*this_it)->visitedBy( *this, this_it );
55  ++this_it;
56  }
58 }
59 
60 void WriterXmlEmitter::visit( TextElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
61 {
62  if( elem.Text.isEmpty() )
63  return;
64 
65  PropertyMap aProps;
66  if( elem.StyleId != -1 )
67  {
68  aProps[ OUString( "text:style-name" ) ] =
70  }
71 
72  m_rEmitContext.rEmitter.beginTag( "text:span", aProps );
73  m_rEmitContext.rEmitter.write( elem.Text.makeStringAndClear() );
74  auto this_it = elem.Children.begin();
75  while( this_it != elem.Children.end() && this_it->get() != &elem )
76  {
77  (*this_it)->visitedBy( *this, this_it );
78  ++this_it;
79  }
80 
81  m_rEmitContext.rEmitter.endTag( "text:span" );
82 }
83 
84 void WriterXmlEmitter::visit( ParagraphElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
85 {
86  PropertyMap aProps;
87  if( elem.StyleId != -1 )
88  {
89  aProps[ "text:style-name" ] = m_rEmitContext.rStyles.getStyleName( elem.StyleId );
90  }
91  const char* pTagType = "text:p";
92  if( elem.Type == ParagraphElement::Headline )
93  pTagType = "text:h";
94  m_rEmitContext.rEmitter.beginTag( pTagType, aProps );
95 
96  auto this_it = elem.Children.begin();
97  while( this_it != elem.Children.end() && this_it->get() != &elem )
98  {
99  (*this_it)->visitedBy( *this, this_it );
100  ++this_it;
101  }
102 
103  m_rEmitContext.rEmitter.endTag( pTagType );
104 }
105 
107  PropertyMap& rProps,
108  const EmitContext& rEmitContext )
109 {
110  double rel_x = rElem.x, rel_y = rElem.y;
111 
112  // find anchor type by recursing though parents
113  Element* pAnchor = &rElem;
114  ParagraphElement* pParaElt = nullptr;
115  PageElement* pPage = nullptr;
116  while ((pAnchor = pAnchor->Parent))
117  {
118  if ((pParaElt = dynamic_cast<ParagraphElement*>(pAnchor)))
119  break;
120  if ((pPage = dynamic_cast<PageElement*>(pAnchor)))
121  break;
122  }
123  if( pAnchor )
124  {
125  if (pParaElt)
126  {
127  rProps[ "text:anchor-type" ] = rElem.isCharacter
128  ? OUStringLiteral("character") : OUStringLiteral("paragraph");
129  }
130  else
131  {
132  assert(pPage); // guaranteed by the while loop above
133  rProps[ "text:anchor-type" ] = "page";
134  rProps[ "text:anchor-page-number" ] = OUString::number(pPage->PageNumber);
135  }
136  rel_x -= pAnchor->x;
137  rel_y -= pAnchor->y;
138  }
139 
140  rProps[ "draw:z-index" ] = OUString::number( rElem.ZOrder );
141  rProps[ "draw:style-name"] = rEmitContext.rStyles.getStyleName( rElem.StyleId );
142  rProps[ "svg:width" ] = convertPixelToUnitString( rElem.w );
143  rProps[ "svg:height" ] = convertPixelToUnitString( rElem.h );
144 
145  const GraphicsContext& rGC =
146  rEmitContext.rProcessor.getGraphicsContext( rElem.GCId );
147  if( rGC.Transformation.isIdentity() )
148  {
149  if( !rElem.isCharacter )
150  {
151  rProps[ "svg:x" ] = convertPixelToUnitString( rel_x );
152  rProps[ "svg:y" ] = convertPixelToUnitString( rel_y );
153  }
154  }
155  else
156  {
157  basegfx::B2DTuple aScale, aTranslation;
158  double fRotate, fShearX;
159 
160  rGC.Transformation.decompose( aScale, aTranslation, fRotate, fShearX );
161 
162  OUStringBuffer aBuf( 256 );
163 
164  // TODO(F2): general transformation case missing; if implemented, note
165  // that ODF rotation is oriented the other way
166 
167  // build transformation string
168  if (rElem.MirrorVertical)
169  {
170  // At some point, rElem.h may start arriving positive,
171  // so use robust adjusting math
172  rel_y -= std::abs(rElem.h);
173  if (!aBuf.isEmpty())
174  aBuf.append(' ');
175  aBuf.append("scale( 1.0 -1.0 )");
176  }
177  if( fShearX != 0.0 )
178  {
179  aBuf.append( "skewX( " );
180  aBuf.append( fShearX );
181  aBuf.append( " )" );
182  }
183  if( fRotate != 0.0 )
184  {
185  if( !aBuf.isEmpty() )
186  aBuf.append( ' ' );
187  aBuf.append( "rotate( " );
188  aBuf.append( -fRotate );
189  aBuf.append( " )" );
190 
191  }
192  if( ! rElem.isCharacter )
193  {
194  if( !aBuf.isEmpty() )
195  aBuf.append( ' ' );
196  aBuf.append( "translate( " );
197  aBuf.append( convertPixelToUnitString( rel_x ) );
198  aBuf.append( ' ' );
199  aBuf.append( convertPixelToUnitString( rel_y ) );
200  aBuf.append( " )" );
201  }
202 
203  rProps[ "draw:transform" ] = aBuf.makeStringAndClear();
204  }
205 }
206 
207 void WriterXmlEmitter::visit( FrameElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
208 {
209  if( elem.Children.empty() )
210  return;
211 
212  bool bTextBox = (dynamic_cast<ParagraphElement*>(elem.Children.front().get()) != nullptr);
213  PropertyMap aFrameProps;
214  fillFrameProps( elem, aFrameProps, m_rEmitContext );
215  m_rEmitContext.rEmitter.beginTag( "draw:frame", aFrameProps );
216  if( bTextBox )
217  m_rEmitContext.rEmitter.beginTag( "draw:text-box", PropertyMap() );
218 
219  auto this_it = elem.Children.begin();
220  while( this_it != elem.Children.end() && this_it->get() != &elem )
221  {
222  (*this_it)->visitedBy( *this, this_it );
223  ++this_it;
224  }
225 
226  if( bTextBox )
227  m_rEmitContext.rEmitter.endTag( "draw:text-box" );
228  m_rEmitContext.rEmitter.endTag( "draw:frame" );
229 }
230 
231 void WriterXmlEmitter::visit( PolyPolyElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
232 {
233  elem.updateGeometry();
234  /* note:
235  * aw recommends using 100dth of mm in all respects since the xml import
236  * (a) is buggy (see issue 37213)
237  * (b) is optimized for 100dth of mm and does not scale itself then,
238  * this does not gain us speed but makes for smaller rounding errors since
239  * the xml importer coordinates are integer based
240  */
241  for (sal_uInt32 i = 0; i< elem.PolyPoly.count(); i++)
242  {
243  basegfx::B2DPolygon b2dPolygon = elem.PolyPoly.getB2DPolygon( i );
244 
245  for ( sal_uInt32 j = 0; j< b2dPolygon.count(); j++ )
246  {
248  basegfx::B2DPoint nextPoint;
249  point = b2dPolygon.getB2DPoint( j );
250 
251  basegfx::B2DPoint prevPoint = b2dPolygon.getPrevControlPoint( j ) ;
252 
253  point.setX( convPx2mmPrec2( point.getX() )*100.0 );
254  point.setY( convPx2mmPrec2( point.getY() )*100.0 );
255 
256  if ( b2dPolygon.isPrevControlPointUsed( j ) )
257  {
258  prevPoint.setX( convPx2mmPrec2( prevPoint.getX() )*100.0 );
259  prevPoint.setY( convPx2mmPrec2( prevPoint.getY() )*100.0 );
260  }
261 
262  if ( b2dPolygon.isNextControlPointUsed( j ) )
263  {
264  nextPoint = b2dPolygon.getNextControlPoint( j ) ;
265  nextPoint.setX( convPx2mmPrec2( nextPoint.getX() )*100.0 );
266  nextPoint.setY( convPx2mmPrec2( nextPoint.getY() )*100.0 );
267  }
268 
269  b2dPolygon.setB2DPoint( j, point );
270 
271  if ( b2dPolygon.isPrevControlPointUsed( j ) )
272  b2dPolygon.setPrevControlPoint( j , prevPoint ) ;
273 
274  if ( b2dPolygon.isNextControlPointUsed( j ) )
275  b2dPolygon.setNextControlPoint( j , nextPoint ) ;
276  }
277 
278  elem.PolyPoly.setB2DPolygon( i, b2dPolygon );
279  }
280 
281  PropertyMap aProps;
282  fillFrameProps( elem, aProps, m_rEmitContext );
283  OUStringBuffer aBuf( 64 );
284  aBuf.append( "0 0 " );
285  aBuf.append( convPx2mmPrec2(elem.w)*100.0 );
286  aBuf.append( ' ' );
287  aBuf.append( convPx2mmPrec2(elem.h)*100.0 );
288  aProps[ "svg:viewBox" ] = aBuf.makeStringAndClear();
289  aProps[ "svg:d" ] = basegfx::utils::exportToSvgD( elem.PolyPoly, true, true, false );
290 
291  m_rEmitContext.rEmitter.beginTag( "draw:path", aProps );
292  m_rEmitContext.rEmitter.endTag( "draw:path" );
293 }
294 
295 void WriterXmlEmitter::visit( ImageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
296 {
297  PropertyMap aImageProps;
298  m_rEmitContext.rEmitter.beginTag( "draw:image", aImageProps );
299  m_rEmitContext.rEmitter.beginTag( "office:binary-data", PropertyMap() );
301  m_rEmitContext.rEmitter.endTag( "office:binary-data" );
302  m_rEmitContext.rEmitter.endTag( "draw:image" );
303 }
304 
305 void WriterXmlEmitter::visit( PageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
306 {
308  m_rEmitContext.xStatusIndicator->setValue( elem.PageNumber );
309 
310  auto this_it = elem.Children.begin();
311  while( this_it != elem.Children.end() && this_it->get() != &elem )
312  {
313  (*this_it)->visitedBy( *this, this_it );
314  ++this_it;
315  }
316 }
317 
318 void WriterXmlEmitter::visit( DocumentElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&)
319 {
320  m_rEmitContext.rEmitter.beginTag( "office:body", PropertyMap() );
321  m_rEmitContext.rEmitter.beginTag( "office:text", PropertyMap() );
322 
323  for( const auto& rxChild : elem.Children )
324  {
325  PageElement* pPage = dynamic_cast<PageElement*>(rxChild.get());
326  if( pPage )
327  {
328  // emit only page anchored objects
329  // currently these are only DrawElement types
330  for( auto child_it = pPage->Children.begin(); child_it != pPage->Children.end(); ++child_it )
331  {
332  if( dynamic_cast<DrawElement*>(child_it->get()) != nullptr )
333  (*child_it)->visitedBy( *this, child_it );
334  }
335  }
336  }
337 
338  // do not emit page anchored objects, they are emitted before
339  // (must precede all pages in writer document) currently these are
340  // only DrawElement types
341  for( auto it = elem.Children.begin(); it != elem.Children.end(); ++it )
342  {
343  if( dynamic_cast<DrawElement*>(it->get()) == nullptr )
344  (*it)->visitedBy( *this, it );
345  }
346 
347  m_rEmitContext.rEmitter.endTag( "office:text" );
348  m_rEmitContext.rEmitter.endTag( "office:body" );
349 }
350 
351 
352 void WriterXmlOptimizer::visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
353 {
354 }
355 
356 void WriterXmlOptimizer::visit( TextElement&, const std::list< std::unique_ptr<Element> >::const_iterator&)
357 {
358 }
359 
360 void WriterXmlOptimizer::visit( FrameElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
361 {
362  elem.applyToChildren(*this);
363 }
364 
365 void WriterXmlOptimizer::visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
366 {
367 }
368 
369 void WriterXmlOptimizer::visit( PolyPolyElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& elemIt )
370 {
371  /* note: optimize two consecutive PolyPolyElements that
372  * have the same path but one of which is a stroke while
373  * the other is a fill
374  */
375  if( !elem.Parent )
376  return;
377  // find following PolyPolyElement in parent's children list
378  if( elemIt == elem.Parent->Children.end() )
379  return;
380  auto next_it = elemIt;
381  ++next_it;
382  if( next_it == elem.Parent->Children.end() )
383  return;
384 
385  PolyPolyElement* pNext = dynamic_cast<PolyPolyElement*>(next_it->get());
386  if( !pNext || pNext->PolyPoly != elem.PolyPoly )
387  return;
388 
389  const GraphicsContext& rNextGC =
391  const GraphicsContext& rThisGC =
393 
394  if( !(rThisGC.BlendMode == rNextGC.BlendMode &&
395  rThisGC.Flatness == rNextGC.Flatness &&
396  rThisGC.Transformation == rNextGC.Transformation &&
397  rThisGC.Clip == rNextGC.Clip &&
398  pNext->Action == PATH_STROKE &&
399  (elem.Action == PATH_FILL || elem.Action == PATH_EOFILL)) )
400  return;
401 
402  GraphicsContext aGC = rThisGC;
403  aGC.LineJoin = rNextGC.LineJoin;
404  aGC.LineCap = rNextGC.LineCap;
405  aGC.LineWidth = rNextGC.LineWidth;
406  aGC.MiterLimit= rNextGC.MiterLimit;
407  aGC.DashArray = rNextGC.DashArray;
408  aGC.LineColor = rNextGC.LineColor;
409  elem.GCId = m_rProcessor.getGCId( aGC );
410 
411  elem.Action |= pNext->Action;
412 
413  elem.Children.splice( elem.Children.end(), pNext->Children );
414  elem.Parent->Children.erase(next_it);
415 }
416 
417 void WriterXmlOptimizer::visit( ParagraphElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt)
418 {
419  optimizeTextElements( elem );
420 
421  elem.applyToChildren(*this);
422 
423  if( !(elem.Parent && rParentIt != elem.Parent->Children.end()) )
424  return;
425 
426  // find if there is a previous paragraph that might be a heading for this one
427  auto prev = rParentIt;
428  ParagraphElement* pPrevPara = nullptr;
429  while( prev != elem.Parent->Children.begin() )
430  {
431  --prev;
432  pPrevPara = dynamic_cast< ParagraphElement* >(prev->get());
433  if( pPrevPara )
434  {
435  /* What constitutes a heading ? current hints are:
436  * - one line only
437  * - not too far away from this paragraph (two heading height max ?)
438  * - font larger or bold
439  * this is of course incomplete
440  * FIXME: improve hints for heading
441  */
442  // check for single line
443  if( pPrevPara->isSingleLined( m_rProcessor ) )
444  {
445  double head_line_height = pPrevPara->getLineHeight( m_rProcessor );
446  if( pPrevPara->y + pPrevPara->h + 2*head_line_height > elem.y )
447  {
448  // check for larger font
449  if( head_line_height > elem.getLineHeight( m_rProcessor ) )
450  {
451  pPrevPara->Type = ParagraphElement::Headline;
452  }
453  else
454  {
455  // check whether text of pPrevPara is bold (at least first text element)
456  // and this para is not bold (dito)
457  TextElement* pPrevText = pPrevPara->getFirstTextChild();
458  TextElement* pThisText = elem.getFirstTextChild();
459  if( pPrevText && pThisText )
460  {
461  const FontAttributes& rPrevFont = m_rProcessor.getFont( pPrevText->FontId );
462  const FontAttributes& rThisFont = m_rProcessor.getFont( pThisText->FontId );
463  if( rPrevFont.isBold && ! rThisFont.isBold )
464  pPrevPara->Type = ParagraphElement::Headline;
465  }
466  }
467  }
468  }
469  break;
470  }
471  }
472 }
473 
474 void WriterXmlOptimizer::visit( PageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
475 {
476  if( m_rProcessor.getStatusIndicator().is() )
477  m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber );
478 
479  // resolve hyperlinks
480  elem.resolveHyperlinks();
481 
482  elem.resolveFontStyles( m_rProcessor ); // underlines and such
483 
484  // FIXME: until hyperlinks and font effects are adjusted for
485  // geometrical search handle them before sorting
487 
488  // find paragraphs in text
489  ParagraphElement* pCurPara = nullptr;
490  std::list< std::unique_ptr<Element> >::iterator page_element, next_page_element;
491  next_page_element = elem.Children.begin();
492  double fCurLineHeight = 0.0; // average height of text items in current para
493  int nCurLineElements = 0; // number of line contributing elements in current para
494  double line_left = elem.w, line_right = 0.0;
495  double column_width = elem.w*0.75; // estimate text width
496  // TODO: guess columns
497  while( next_page_element != elem.Children.end() )
498  {
499  page_element = next_page_element++;
500  ParagraphElement* pPagePara = dynamic_cast<ParagraphElement*>(page_element->get());
501  if( pPagePara )
502  {
503  pCurPara = pPagePara;
504  // adjust line height and text items
505  fCurLineHeight = 0.0;
506  nCurLineElements = 0;
507  for( const auto& rxChild : pCurPara->Children )
508  {
509  TextElement* pTestText = dynamic_cast<TextElement*>(rxChild.get());
510  if( pTestText )
511  {
512  fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pTestText->h)/double(nCurLineElements+1);
513  nCurLineElements++;
514  }
515  }
516  continue;
517  }
518 
519  HyperlinkElement* pLink = dynamic_cast<HyperlinkElement*>(page_element->get());
520  DrawElement* pDraw = dynamic_cast<DrawElement*>(page_element->get());
521  if( ! pDraw && pLink && ! pLink->Children.empty() )
522  pDraw = dynamic_cast<DrawElement*>(pLink->Children.front().get() );
523  if( pDraw )
524  {
525  // insert small drawing objects as character, else leave them page bound
526 
527  bool bInsertToParagraph = false;
528  // first check if this is either inside the paragraph
529  if( pCurPara && pDraw->y < pCurPara->y + pCurPara->h )
530  {
531  if( pDraw->h < fCurLineHeight * 1.5 )
532  {
533  bInsertToParagraph = true;
534  fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pDraw->h)/double(nCurLineElements+1);
535  nCurLineElements++;
536  // mark draw element as character
537  pDraw->isCharacter = true;
538  }
539  }
540  // or perhaps the draw element begins a new paragraph
541  else if( next_page_element != elem.Children.end() )
542  {
543  TextElement* pText = dynamic_cast<TextElement*>(next_page_element->get());
544  if( ! pText )
545  {
546  ParagraphElement* pPara = dynamic_cast<ParagraphElement*>(next_page_element->get());
547  if( pPara && ! pPara->Children.empty() )
548  pText = dynamic_cast<TextElement*>(pPara->Children.front().get());
549  }
550  if( pText && // check there is a text
551  pDraw->h < pText->h*1.5 && // and it is approx the same height
552  // and either upper or lower edge of pDraw is inside text's vertical range
553  ( ( pDraw->y >= pText->y && pDraw->y <= pText->y+pText->h ) ||
554  ( pDraw->y+pDraw->h >= pText->y && pDraw->y+pDraw->h <= pText->y+pText->h )
555  )
556  )
557  {
558  bInsertToParagraph = true;
559  fCurLineHeight = pDraw->h;
560  nCurLineElements = 1;
561  line_left = pDraw->x;
562  line_right = pDraw->x + pDraw->w;
563  // begin a new paragraph
564  pCurPara = nullptr;
565  // mark draw element as character
566  pDraw->isCharacter = true;
567  }
568  }
569 
570  if( ! bInsertToParagraph )
571  {
572  pCurPara = nullptr;
573  continue;
574  }
575  }
576 
577  TextElement* pText = dynamic_cast<TextElement*>(page_element->get());
578  if( ! pText && pLink && ! pLink->Children.empty() )
579  pText = dynamic_cast<TextElement*>(pLink->Children.front().get());
580  if( pText )
581  {
582  Element* pGeo = pLink ? static_cast<Element*>(pLink) :
583  static_cast<Element*>(pText);
584  if( pCurPara )
585  {
586  // there was already a text element, check for a new paragraph
587  if( nCurLineElements > 0 )
588  {
589  // if the new text is significantly distant from the paragraph
590  // begin a new paragraph
591  if( pGeo->y > pCurPara->y+pCurPara->h + fCurLineHeight*0.5 )
592  pCurPara = nullptr; // insert new paragraph
593  else if( pGeo->y > (pCurPara->y+pCurPara->h - fCurLineHeight*0.05) )
594  {
595  // new paragraph if either the last line of the paragraph
596  // was significantly shorter than the paragraph as a whole
597  if( (line_right - line_left) < pCurPara->w*0.75 )
598  pCurPara = nullptr;
599  // or the last line was significantly smaller than the column width
600  else if( (line_right - line_left) < column_width*0.75 )
601  pCurPara = nullptr;
602  }
603  }
604  }
605  // update line height/width
606  if( pCurPara )
607  {
608  fCurLineHeight = (fCurLineHeight*double(nCurLineElements) + pGeo->h)/double(nCurLineElements+1);
609  nCurLineElements++;
610  if( pGeo->x < line_left )
611  line_left = pGeo->x;
612  if( pGeo->x+pGeo->w > line_right )
613  line_right = pGeo->x+pGeo->w;
614  }
615  else
616  {
617  fCurLineHeight = pGeo->h;
618  nCurLineElements = 1;
619  line_left = pGeo->x;
620  line_right = pGeo->x + pGeo->w;
621  }
622  }
623 
624  // move element to current paragraph
625  if( ! pCurPara ) // new paragraph, insert one
626  {
627  pCurPara = ElementFactory::createParagraphElement( nullptr );
628  // set parent
629  pCurPara->Parent = &elem;
630  //insert new paragraph before current element
631  page_element = elem.Children.insert( page_element, std::unique_ptr<Element>(pCurPara) );
632  // forward iterator to current element again
633  ++ page_element;
634  // update next_element which is now invalid
635  next_page_element = page_element;
636  ++ next_page_element;
637  }
638  Element* pCurEle = page_element->get();
639  Element::setParent( page_element, pCurPara );
640  OSL_ENSURE( !pText || pCurEle == pText || pCurEle == pLink, "paragraph child list in disorder" );
641  if( pText || pDraw )
642  pCurPara->updateGeometryWith( pCurEle );
643  }
644 
645  // process children
646  elem.applyToChildren(*this);
647 
648  // find possible header and footer
649  checkHeaderAndFooter( elem );
650 }
651 
653 {
654  /* indicators for a header:
655  * - single line paragraph at top of page (inside 15% page height)
656  * - at least lineheight above the next paragraph
657  *
658  * indicators for a footer likewise:
659  * - single line paragraph at bottom of page (inside 15% page height)
660  * - at least lineheight below the previous paragraph
661  */
662 
663  auto isParagraphElement = [](std::unique_ptr<Element>& rxChild) -> bool {
664  return dynamic_cast<ParagraphElement*>(rxChild.get()) != nullptr;
665  };
666 
667  // detect header
668  // Note: the following assumes that the pages' children have been
669  // sorted geometrically
670  auto it = std::find_if(rElem.Children.begin(), rElem.Children.end(), isParagraphElement);
671  if (it != rElem.Children.end())
672  {
673  ParagraphElement& rPara = dynamic_cast<ParagraphElement&>(**it);
674  if( rPara.y+rPara.h < rElem.h*0.15 && rPara.isSingleLined( m_rProcessor ) )
675  {
676  auto next_it = it;
677  ParagraphElement* pNextPara = nullptr;
678  while( ++next_it != rElem.Children.end() && pNextPara == nullptr )
679  {
680  pNextPara = dynamic_cast<ParagraphElement*>(next_it->get());
681  }
682  if( pNextPara && pNextPara->y > rPara.y+rPara.h*2 )
683  {
684  rElem.HeaderElement = std::move(*it);
685  rPara.Parent = nullptr;
686  rElem.Children.erase( it );
687  }
688  }
689  }
690 
691  // detect footer
692  auto rit = std::find_if(rElem.Children.rbegin(), rElem.Children.rend(), isParagraphElement);
693  if (rit == rElem.Children.rend())
694  return;
695 
696  ParagraphElement& rPara = dynamic_cast<ParagraphElement&>(**rit);
697  if( !(rPara.y > rElem.h*0.85 && rPara.isSingleLined( m_rProcessor )) )
698  return;
699 
700  std::list< std::unique_ptr<Element> >::reverse_iterator next_it = rit;
701  ParagraphElement* pNextPara = nullptr;
702  while( ++next_it != rElem.Children.rend() && pNextPara == nullptr )
703  {
704  pNextPara = dynamic_cast<ParagraphElement*>(next_it->get());
705  }
706  if( pNextPara && pNextPara->y < rPara.y-rPara.h*2 )
707  {
708  rElem.FooterElement = std::move(*rit);
709  rPara.Parent = nullptr;
710  rElem.Children.erase( std::next(rit).base() );
711  }
712 }
713 
715 {
716  if( rParent.Children.empty() ) // this should not happen
717  {
718  OSL_FAIL( "empty paragraph optimized" );
719  return;
720  }
721 
722  // concatenate child elements with same font id
723  auto next = rParent.Children.begin();
724  auto it = next++;
725  FrameElement* pFrame = dynamic_cast<FrameElement*>(rParent.Parent);
726  bool bRotatedFrame = false;
727  if( pFrame )
728  {
729  const GraphicsContext& rFrameGC = m_rProcessor.getGraphicsContext( pFrame->GCId );
730  if( rFrameGC.isRotatedOrSkewed() )
731  bRotatedFrame = true;
732  }
733  while( next != rParent.Children.end() )
734  {
735  bool bConcat = false;
736  TextElement* pCur = dynamic_cast<TextElement*>(it->get());
737  if( pCur )
738  {
739  TextElement* pNext = dynamic_cast<TextElement*>(next->get());
740  if( pNext )
741  {
742  const GraphicsContext& rCurGC = m_rProcessor.getGraphicsContext( pCur->GCId );
743  const GraphicsContext& rNextGC = m_rProcessor.getGraphicsContext( pNext->GCId );
744 
745  // line and space optimization; works only in strictly horizontal mode
746 
747  if( !bRotatedFrame
748  && ! rCurGC.isRotatedOrSkewed()
749  && ! rNextGC.isRotatedOrSkewed()
750  && ! pNext->Text.isEmpty()
751  && pNext->Text[0] != ' '
752  && ! pCur->Text.isEmpty()
753  && pCur->Text[pCur->Text.getLength() - 1] != ' '
754  )
755  {
756  // check for new line in paragraph
757  if( pNext->y > pCur->y+pCur->h )
758  {
759  // new line begins
760  // check whether a space would should be inserted or a hyphen removed
761  sal_Unicode aLastCode = pCur->Text[pCur->Text.getLength() - 1];
762  if( aLastCode == '-'
763  || aLastCode == 0x2010
764  || (aLastCode >= 0x2012 && aLastCode <= 0x2015)
765  || aLastCode == 0xff0d
766  )
767  {
768  // cut a hyphen
769  pCur->Text.setLength( pCur->Text.getLength()-1 );
770  }
771  // append a space unless there is a non breaking hyphen
772  else if( aLastCode != 0x2011 )
773  {
774  pCur->Text.append( ' ' );
775  }
776  }
777  else // we're continuing the same line
778  {
779  // check whether a space would should be inserted
780  // check for a small horizontal offset
781  if( pCur->x + pCur->w + pNext->h*0.15 < pNext->x )
782  {
783  pCur->Text.append( ' ' );
784  }
785  }
786  }
787  // concatenate consecutive text elements unless there is a
788  // font or text color or matrix change, leave a new span in that case
789  if( pCur->FontId == pNext->FontId &&
790  rCurGC.FillColor.Red == rNextGC.FillColor.Red &&
791  rCurGC.FillColor.Green == rNextGC.FillColor.Green &&
792  rCurGC.FillColor.Blue == rNextGC.FillColor.Blue &&
793  rCurGC.FillColor.Alpha == rNextGC.FillColor.Alpha &&
794  rCurGC.Transformation == rNextGC.Transformation
795  )
796  {
797  pCur->updateGeometryWith( pNext );
798  // append text to current element
799  pCur->Text.append( pNext->Text );
800  // append eventual children to current element
801  // and clear children (else the children just
802  // appended to pCur would be destroyed)
803  pCur->Children.splice( pCur->Children.end(), pNext->Children );
804  // get rid of the now useless element
805  rParent.Children.erase( next );
806  bConcat = true;
807  }
808  }
809  }
810  else if( dynamic_cast<HyperlinkElement*>(it->get()) )
811  optimizeTextElements( **it );
812  if( bConcat )
813  {
814  next = it;
815  ++next;
816  }
817  else
818  {
819  ++it;
820  ++next;
821  }
822  }
823 }
824 
825 void WriterXmlOptimizer::visit( DocumentElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&)
826 {
827  elem.applyToChildren(*this);
828 }
829 
830 
831 void WriterXmlFinalizer::visit( PolyPolyElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
832 {
833  // xxx TODO copied from DrawElement
835  PropertyMap aProps;
836  aProps[ "style:family" ] = "graphic";
837 
838  PropertyMap aGCProps;
839  if (elem.Action & PATH_STROKE)
840  {
842  if (rGC.DashArray.size() < 2)
843  {
844  aGCProps[ "draw:stroke" ] = "solid";
845  }
846  else
847  {
849  FillDashStyleProps(props, rGC.DashArray, scale);
850  StyleContainer::Style style("draw:stroke-dash", props);
851 
852  aGCProps[ "draw:stroke" ] = "dash";
853  aGCProps[ "draw:stroke-dash" ] =
856  }
857 
858  aGCProps[ "svg:stroke-color" ] = getColorString(rGC.LineColor);
859  aGCProps[ "svg:stroke-width" ] = convertPixelToUnitString(rGC.LineWidth * scale);
860  aGCProps[ "draw:stroke-linejoin" ] = rGC.GetLineJoinString();
861  aGCProps[ "svg:stroke-linecap" ] = rGC.GetLineCapString();
862  }
863  else
864  {
865  aGCProps[ "draw:stroke" ] = "none";
866  }
867 
868  // TODO(F1): check whether stuff could be emulated by gradient/bitmap/hatch
869  if( elem.Action & (PATH_FILL | PATH_EOFILL) )
870  {
871  aGCProps[ "draw:fill" ] = "solid";
872  aGCProps[ "draw:fill-color" ] = getColorString( rGC.FillColor );
873  }
874  else
875  {
876  aGCProps[ "draw:fill" ] = "none";
877  }
878 
879  StyleContainer::Style aStyle( "style:style", aProps );
880  StyleContainer::Style aSubStyle( "style:graphic-properties", aGCProps );
881  aStyle.SubStyles.push_back( &aSubStyle );
882 
883  elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
884 }
885 
886 void WriterXmlFinalizer::visit( HyperlinkElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
887 {
888 }
889 
890 void WriterXmlFinalizer::visit( TextElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
891 {
892  const FontAttributes& rFont = m_rProcessor.getFont( elem.FontId );
893  PropertyMap aProps;
894  aProps[ "style:family" ] = "text";
895 
896  PropertyMap aFontProps;
897 
898  // family name
899  aFontProps[ "fo:font-family" ] = rFont.familyName;
900  // bold
901  if( rFont.isBold )
902  {
903  aFontProps[ "fo:font-weight" ] = "bold";
904  aFontProps[ "fo:font-weight-asian" ] = "bold";
905  aFontProps[ "fo:font-weight-complex" ] = "bold";
906  }
907  // italic
908  if( rFont.isItalic )
909  {
910  aFontProps[ "fo:font-style" ] = "italic";
911  aFontProps[ "fo:font-style-asian" ] = "italic";
912  aFontProps[ "fo:font-style-complex" ] = "italic";
913  }
914  // underline
915  if( rFont.isUnderline )
916  {
917  aFontProps[ "style:text-underline-style" ] = "solid";
918  aFontProps[ "style:text-underline-width" ] = "auto";
919  aFontProps[ "style:text-underline-color" ] = "font-color";
920  }
921  // outline
922  if( rFont.isOutline )
923  {
924  aFontProps[ "style:text-outline" ] = "true";
925  }
926  // size
927  OUString aFSize = OUString::number( rFont.size*72/PDFI_OUTDEV_RESOLUTION ) + "pt";
928  aFontProps[ "fo:font-size" ] = aFSize;
929  aFontProps[ "style:font-size-asian" ] = aFSize;
930  aFontProps[ "style:font-size-complex" ] = aFSize;
931  // color
933  aFontProps[ "fo:color" ] = getColorString( rFont.isOutline ? rGC.LineColor : rGC.FillColor );
934 
935  StyleContainer::Style aStyle( "style:style", aProps );
936  StyleContainer::Style aSubStyle( "style:text-properties", aFontProps );
937  aStyle.SubStyles.push_back( &aSubStyle );
938  elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
939 }
940 
941 void WriterXmlFinalizer::visit( ParagraphElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& rParentIt )
942 {
943  PropertyMap aParaProps;
944 
945  if( elem.Parent )
946  {
947  // check for center alignment
948  // criterion: paragraph is small relative to parent and distributed around its center
949  double p_x = elem.Parent->x;
950  double p_w = elem.Parent->w;
951 
952  PageElement* pPage = dynamic_cast<PageElement*>(elem.Parent);
953  if( pPage )
954  {
955  p_x += pPage->LeftMargin;
956  p_w -= pPage->LeftMargin+pPage->RightMargin;
957  }
958  bool bIsCenter = false;
959  if( elem.w < ( p_w/2) )
960  {
961  double delta = elem.w/4;
962  // allow very small paragraphs to deviate a little more
963  // relative to parent's center
964  if( elem.w < p_w/8 )
965  delta = elem.w;
966  if( fabs( elem.x+elem.w/2 - ( p_x+ p_w/2) ) < delta ||
967  (pPage && fabs( elem.x+elem.w/2 - (pPage->x + pPage->w/2) ) < delta) )
968  {
969  bIsCenter = true;
970  aParaProps[ "fo:text-align" ] = "center";
971  }
972  }
973  if( ! bIsCenter && elem.x > p_x + p_w/10 )
974  {
975  // indent
976  OUStringBuffer aBuf( 32 );
977  aBuf.append( convPx2mm( elem.x - p_x ) );
978  aBuf.append( "mm" );
979  aParaProps[ "fo:margin-left" ] = aBuf.makeStringAndClear();
980  }
981 
982  // check whether to leave some space to next paragraph
983  // find whether there is a next paragraph
984  auto it = rParentIt;
985  const ParagraphElement* pNextPara = nullptr;
986  while( ++it != elem.Parent->Children.end() && ! pNextPara )
987  pNextPara = dynamic_cast< const ParagraphElement* >(it->get());
988  if( pNextPara )
989  {
990  if( pNextPara->y - (elem.y+elem.h) > convmm2Px( 10 ) )
991  {
992  OUStringBuffer aBuf( 32 );
993  aBuf.append( convPx2mm( pNextPara->y - (elem.y+elem.h) ) );
994  aBuf.append( "mm" );
995  aParaProps[ "fo:margin-bottom" ] = aBuf.makeStringAndClear();
996  }
997  }
998  }
999 
1000  if( ! aParaProps.empty() )
1001  {
1002  PropertyMap aProps;
1003  aProps[ "style:family" ] = "paragraph";
1004  StyleContainer::Style aStyle( "style:style", aProps );
1005  StyleContainer::Style aSubStyle( "style:paragraph-properties", aParaProps );
1006  aStyle.SubStyles.push_back( &aSubStyle );
1007  elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
1008  }
1009 
1010  elem.applyToChildren(*this);
1011 }
1012 
1013 void WriterXmlFinalizer::visit( FrameElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator&)
1014 {
1015  PropertyMap aProps;
1016  aProps[ "style:family" ] = "graphic";
1017 
1018  PropertyMap aGCProps;
1019 
1020  aGCProps[ "draw:stroke" ] = "none";
1021  aGCProps[ "draw:fill" ] = "none";
1022  aGCProps[ "draw:auto-grow-height" ] = "true";
1023  aGCProps[ "draw:auto-grow-width" ] = "true";
1024  aGCProps[ "draw:textarea-horizontal-align" ] = "left";
1025  aGCProps[ "draw:textarea-vertical-align" ] = "top";
1026  aGCProps[ "fo:min-height"] = "0cm";
1027  aGCProps[ "fo:min-width"] = "0cm";
1028  aGCProps[ "fo:padding-top" ] = "0cm";
1029  aGCProps[ "fo:padding-left" ] = "0cm";
1030  aGCProps[ "fo:padding-right" ] = "0cm";
1031  aGCProps[ "fo:padding-bottom" ] = "0cm";
1032 
1033  StyleContainer::Style aStyle( "style:style", aProps );
1034  StyleContainer::Style aSubStyle( "style:graphic-properties", aGCProps );
1035  aStyle.SubStyles.push_back( &aSubStyle );
1036 
1037  elem.StyleId = m_rStyleContainer.getStyleId( aStyle );
1038  elem.applyToChildren(*this);
1039 }
1040 
1041 void WriterXmlFinalizer::visit( ImageElement&, const std::list< std::unique_ptr<Element> >::const_iterator& )
1042 {
1043 }
1044 
1046  StyleContainer& rStyles,
1047  const OUString& rMasterPageName )
1048 {
1049  PropertyMap aProps;
1050  if( rElem.StyleId != -1 )
1051  {
1052  const PropertyMap* pProps = rStyles.getProperties( rElem.StyleId );
1053  if( pProps )
1054  aProps = *pProps;
1055  }
1056 
1057  aProps[ "style:family" ] = "paragraph";
1058  aProps[ "style:master-page-name" ] = rMasterPageName;
1059 
1060  if( rElem.StyleId != -1 )
1061  rElem.StyleId = rStyles.setProperties( rElem.StyleId, aProps );
1062  else
1063  {
1064  StyleContainer::Style aStyle( "style:style", aProps );
1065  rElem.StyleId = rStyles.getStyleId( aStyle );
1066  }
1067 }
1068 
1069 void WriterXmlFinalizer::visit( PageElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
1070 {
1071  if( m_rProcessor.getStatusIndicator().is() )
1072  m_rProcessor.getStatusIndicator()->setValue( elem.PageNumber );
1073 
1074  // transform from pixel to mm
1075  double page_width = convPx2mm( elem.w ), page_height = convPx2mm( elem.h );
1076 
1077  // calculate page margins out of the relevant children (paragraphs)
1078  elem.TopMargin = elem.h;
1079  elem.BottomMargin = 0;
1080  elem.LeftMargin = elem.w;
1081  elem.RightMargin = 0;
1082  // first element should be a paragraph
1083  ParagraphElement* pFirstPara = nullptr;
1084  for( const auto& rxChild : elem.Children )
1085  {
1086  if( dynamic_cast<ParagraphElement*>( rxChild.get() ) )
1087  {
1088  if( rxChild->x < elem.LeftMargin )
1089  elem.LeftMargin = rxChild->x;
1090  if( rxChild->y < elem.TopMargin )
1091  elem.TopMargin = rxChild->y;
1092  if( rxChild->x + rxChild->w > elem.w - elem.RightMargin )
1093  elem.RightMargin = elem.w - (rxChild->x + rxChild->w);
1094  if( rxChild->y + rxChild->h > elem.h - elem.BottomMargin )
1095  elem.BottomMargin = elem.h - (rxChild->y + rxChild->h);
1096  if( ! pFirstPara )
1097  pFirstPara = dynamic_cast<ParagraphElement*>( rxChild.get() );
1098  }
1099  }
1100  if( elem.HeaderElement && elem.HeaderElement->y < elem.TopMargin )
1101  elem.TopMargin = elem.HeaderElement->y;
1102  if( elem.FooterElement && elem.FooterElement->y+elem.FooterElement->h > elem.h - elem.BottomMargin )
1103  elem.BottomMargin = elem.h - (elem.FooterElement->y + elem.FooterElement->h);
1104 
1105  // transform margins to mm
1106  double left_margin = convPx2mm( elem.LeftMargin );
1107  double right_margin = convPx2mm( elem.RightMargin );
1108  double top_margin = convPx2mm( elem.TopMargin );
1109  double bottom_margin = convPx2mm( elem.BottomMargin );
1110  if( ! pFirstPara )
1111  {
1112  // use default page margins
1113  left_margin = 10;
1114  right_margin = 10;
1115  top_margin = 10;
1116  bottom_margin = 10;
1117  }
1118 
1119  // round left/top margin to nearest mm
1120  left_margin = rtl_math_round( left_margin, 0, rtl_math_RoundingMode_Floor );
1121  top_margin = rtl_math_round( top_margin, 0, rtl_math_RoundingMode_Floor );
1122  // round (fuzzy) right/bottom margin to nearest cm
1123  right_margin = rtl_math_round( right_margin, right_margin >= 10 ? -1 : 0, rtl_math_RoundingMode_Floor );
1124  bottom_margin = rtl_math_round( bottom_margin, bottom_margin >= 10 ? -1 : 0, rtl_math_RoundingMode_Floor );
1125 
1126  // set reasonable default in case of way too large margins
1127  // e.g. no paragraph case
1128  if( left_margin > page_width/2.0 - 10 )
1129  left_margin = 10;
1130  if( right_margin > page_width/2.0 - 10 )
1131  right_margin = 10;
1132  if( top_margin > page_height/2.0 - 10 )
1133  top_margin = 10;
1134  if( bottom_margin > page_height/2.0 - 10 )
1135  bottom_margin = 10;
1136 
1137  // catch the weird cases
1138  if( left_margin < 0 )
1139  left_margin = 0;
1140  if( right_margin < 0 )
1141  right_margin = 0;
1142  if( top_margin < 0 )
1143  top_margin = 0;
1144  if( bottom_margin < 0 )
1145  bottom_margin = 0;
1146 
1147  // widely differing margins are unlikely to be correct
1148  if( right_margin > left_margin*1.5 )
1149  right_margin = left_margin;
1150 
1151  elem.LeftMargin = convmm2Px( left_margin );
1152  elem.RightMargin = convmm2Px( right_margin );
1153  elem.TopMargin = convmm2Px( top_margin );
1154  elem.BottomMargin = convmm2Px( bottom_margin );
1155 
1156  // get styles for paragraphs
1157  PropertyMap aPageProps;
1158  PropertyMap aPageLayoutProps;
1159  aPageLayoutProps[ "fo:page-width" ] = unitMMString( page_width );
1160  aPageLayoutProps[ "fo:page-height" ] = unitMMString( page_height );
1161  aPageLayoutProps[ "style:print-orientation" ]
1162  = elem.w < elem.h ? OUStringLiteral("portrait") : OUStringLiteral("landscape");
1163  aPageLayoutProps[ "fo:margin-top" ] = unitMMString( top_margin );
1164  aPageLayoutProps[ "fo:margin-bottom" ] = unitMMString( bottom_margin );
1165  aPageLayoutProps[ "fo:margin-left" ] = unitMMString( left_margin );
1166  aPageLayoutProps[ "fo:margin-right" ] = unitMMString( right_margin );
1167  aPageLayoutProps[ "style:writing-mode" ]= "lr-tb";
1168 
1169  StyleContainer::Style aStyle( "style:page-layout", aPageProps);
1170  StyleContainer::Style aSubStyle( "style:page-layout-properties", aPageLayoutProps);
1171  aStyle.SubStyles.push_back(&aSubStyle);
1172  sal_Int32 nPageStyle = m_rStyleContainer.impl_getStyleId( aStyle, false );
1173 
1174  // create master page
1175  OUString aMasterPageLayoutName = m_rStyleContainer.getStyleName( nPageStyle );
1176  aPageProps[ "style:page-layout-name" ] = aMasterPageLayoutName;
1177  StyleContainer::Style aMPStyle( "style:master-page", aPageProps );
1178  StyleContainer::Style aHeaderStyle( "style:header", PropertyMap() );
1179  StyleContainer::Style aFooterStyle( "style:footer", PropertyMap() );
1180  if( elem.HeaderElement )
1181  {
1182  elem.HeaderElement->visitedBy( *this, std::list<std::unique_ptr<Element>>::iterator() );
1183  aHeaderStyle.ContainedElement = elem.HeaderElement.get();
1184  aMPStyle.SubStyles.push_back( &aHeaderStyle );
1185  }
1186  if( elem.FooterElement )
1187  {
1188  elem.FooterElement->visitedBy( *this, std::list<std::unique_ptr<Element>>::iterator() );
1189  aFooterStyle.ContainedElement = elem.FooterElement.get();
1190  aMPStyle.SubStyles.push_back( &aFooterStyle );
1191  }
1192  elem.StyleId = m_rStyleContainer.impl_getStyleId( aMPStyle,false );
1193 
1194 
1195  OUString aMasterPageName = m_rStyleContainer.getStyleName( elem.StyleId );
1196 
1197  // create styles for children
1198  elem.applyToChildren(*this);
1199 
1200  // no paragraph or other elements before the first paragraph
1201  if( ! pFirstPara )
1202  {
1203  pFirstPara = ElementFactory::createParagraphElement( nullptr );
1204  pFirstPara->Parent = &elem;
1205  elem.Children.push_front( std::unique_ptr<Element>(pFirstPara) );
1206  }
1207  setFirstOnPage(*pFirstPara, m_rStyleContainer, aMasterPageName);
1208 }
1209 
1210 void WriterXmlFinalizer::visit( DocumentElement& elem, const std::list< std::unique_ptr<Element> >::const_iterator& )
1211 {
1212  elem.applyToChildren(*this);
1213 }
1214 
1215 }
1216 
1217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::rendering::ARGBColor LineColor
Definition: pdfihelper.hxx:96
std::unordered_map< OUString, OUString > PropertyMap
Definition: pdfihelper.hxx:44
StyleContainer & m_rStyleContainer
void setX(double fX)
basegfx::B2DPolyPolygon PolyPoly
basegfx::B2DPoint getNextControlPoint(sal_uInt32 nIndex) const
bool isRotatedOrSkewed() const
Definition: pdfihelper.hxx:177
OUString unitMMString(double fMM)
Definition: pdfihelper.cxx:108
static void fillFrameProps(DrawElement &rElem, PropertyMap &rProps, const EmitContext &rEmitContext)
#define PDFI_OUTDEV_RESOLUTION
Definition: pdfihelper.hxx:38
double convmm2Px(double fMM)
Definition: pdfihelper.hxx:60
bool isSingleLined(PDFIProcessor const &rProc) const
std::vector< Style * > SubStyles
Definition: style.hxx:45
void applyToChildren(ElementTreeVisitor &)
Apply visitor to all children.
static ParagraphElement * createParagraphElement(Element *pParent)
virtual void visit(HyperlinkElement &, const std::list< std::unique_ptr< Element > >::const_iterator &) override
double getX() const
virtual void beginTag(const char *pTag, const PropertyMap &rProperties)=0
Open up a tag with the given properties.
virtual void visit(HyperlinkElement &, const std::list< std::unique_ptr< Element > >::const_iterator &) override
OUString convertPixelToUnitString(double fPix)
Definition: pdfihelper.cxx:117
void setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon &rPolygon)
aBuf
sal_Int32 impl_getStyleId(const Style &rStyle, bool bSubStyle)
Definition: style.cxx:37
Element * ContainedElement
Definition: style.hxx:44
double getY() const
def point()
const FontAttributes & getFont(sal_Int32 nFontId) const
sal_uInt16 sal_Unicode
B2DPolygon const & getB2DPolygon(sal_uInt32 nIndex) const
basegfx::B2DPolyPolygon Clip
Definition: pdfihelper.hxx:108
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
PDFIProcessor & rProcessor
bool isPrevControlPointUsed(sal_uInt32 nIndex) const
std::unique_ptr< Element > HeaderElement
TextElement * getFirstTextChild() const
void setB2DPoint(sal_uInt32 nIndex, const basegfx::B2DPoint &rValue)
css::rendering::ARGBColor FillColor
Definition: pdfihelper.hxx:97
const GraphicsContext & getGraphicsContext(sal_Int32 nGCId) const
double convPx2mm(double fPix)
Definition: pdfihelper.hxx:53
void optimizeTextElements(Element &rParent)
std::vector< double > DashArray
Definition: pdfihelper.hxx:104
std::unique_ptr< Element > FooterElement
ImageContainer & rImages
sal_Int32 getGCId(const GraphicsContext &rGC)
const PropertyMap * getProperties(sal_Int32 nStyleId) const
Definition: style.cxx:86
css::uno::Reference< css::task::XStatusIndicator > xStatusIndicator
std::list< std::unique_ptr< Element > > Children
OUString GetLineJoinString() const
Definition: pdfihelper.hxx:149
virtual void visit(HyperlinkElement &, const std::list< std::unique_ptr< Element > >::const_iterator &) override
int i
sal_Int32 setProperties(sal_Int32 nStyleId, const PropertyMap &rNewProps)
Definition: style.cxx:93
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
double GetAverageTransformationScale(const basegfx::B2DHomMatrix &matrix)
Definition: pdfihelper.cxx:32
void const * base
basegfx::B2DHomMatrix Transformation
Definition: pdfihelper.hxx:107
void resolveFontStyles(PDFIProcessor const &rProc)
sal_Int32 scale
OUString getStyleName(sal_Int32 nStyle) const
Definition: style.cxx:146
OUString getColorString(const css::rendering::ARGBColor &)
Convert color to "#FEFEFE" color notation.
basegfx::B2DPoint getPrevControlPoint(sal_uInt32 nIndex) const
void setNextControlPoint(sal_uInt32 nIndex, const basegfx::B2DPoint &rValue)
dictionary props
virtual void visitedBy(ElementTreeVisitor &, const std::list< std::unique_ptr< Element > >::const_iterator &rParentIt) override
To be implemented by every tree node that needs to be visitable.
bool isIdentity() const
StyleContainer & rStyles
void FillDashStyleProps(PropertyMap &props, const std::vector< double > &dashArray, double scale)
Definition: pdfihelper.cxx:40
exports com.sun.star. style
static void setFirstOnPage(ParagraphElement &rElem, StyleContainer &rStyles, const OUString &rMasterPageName)
const css::uno::Reference< css::task::XStatusIndicator > & getStatusIndicator() const
bool isNextControlPointUsed(sal_uInt32 nIndex) const
void updateGeometryWith(const Element *pMergeFrom)
Union element geometry with given element.
void checkHeaderAndFooter(PageElement &rElem)
sal_uInt32 count() const
void setY(double fY)
SvBaseLink * pLink
double convPx2mmPrec2(double fPix)
Definition: pdfihelper.hxx:67
static void setParent(std::list< std::unique_ptr< Element >>::iterator const &el, Element *pNewParent)
el must be a valid dereferenceable iterator of el->Parent->Children pNewParent must not be NULL ...
sal_Int32 getStyleId(const Style &rStyle)
Definition: style.hxx:152
static void sortElements(Element *pElement)
XmlEmitter & rEmitter
OUString exportToSvgD(const B2DPolyPolygon &rPolyPoly, bool bUseRelativeCoordinates, bool bDetectQuadraticBeziers, bool bHandleRelativeNextPointCompatible, bool bOOXMLMotionPath=false)
double getLineHeight(PDFIProcessor &rProc) const
void writeBase64EncodedStream(ImageId nImageId, EmitContext &rContext)
OUString GetLineCapString() const
Definition: pdfihelper.hxx:163
virtual void write(const OUString &rString)=0
Write PCTEXT as-is to output.
void setPrevControlPoint(sal_uInt32 nIndex, const basegfx::B2DPoint &rValue)
OUStringBuffer Text
virtual void endTag(const char *pTag)=0
Close previously opened tag.
sal_uInt32 count() const
basegfx::B2DPoint const & getB2DPoint(sal_uInt32 nIndex) const