/* -*- 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 .
*/
void PDFIProcessor::setFont( const FontAttributes& i_rFont )
{
FontAttributes aChangedFont( i_rFont );
GraphicsContext& rGC=getCurrentContext(); // for text render modes, please see PDF reference manual if (rGC.TextRenderMode == 1)
{
aChangedFont.isOutline = true;
} elseif (rGC.TextRenderMode == 2)
{ // tdf#81484: faux bold is represented as "stroke+fill" (while using the same color for both stroke and fill) in pdf. // Convert to bold instead if the stroke color is the same as the fill color, // otherwise it should be outline. if (getCurrentContext().LineColor == getCurrentContext().FillColor)
aChangedFont.fontWeight = u"bold"_ustr; else
aChangedFont.isOutline = true;
}
FontToIdMap::const_iterator it = m_aFontToId.find( aChangedFont ); if( it != m_aFontToId.end() )
rGC.FontId = it->second; else
{
m_aFontToId[ aChangedFont ] = m_nNextFontId;
m_aIdToFont[ m_nNextFontId ] = std::move(aChangedFont);
rGC.FontId = m_nNextFontId;
m_nNextFontId++;
}
}
// If space glyph is not found, use average glyph width instead if (spaceDetectBoundary == 0.0)
{ double avgGlyphWidth = 0.0; for (const CharGlyph & i : m_GlyphsList)
avgGlyphWidth += i.getWidth();
avgGlyphWidth /= m_GlyphsList.size();
spaceDetectBoundary = avgGlyphWidth * 0.2;
}
// Poppler wrapper takes into account that vertical axes of PDF and ODF are opposite, // and it flips matrix vertically (see poppler's GfxState::GfxState()). // But image internal vertical axis is independent of PDF vertical axis direction, // so arriving matrix is extra-flipped relative to image. // We force vertical flip here to compensate that.
pFrame->MirrorVertical = true;
}
auto aB2DPoly = basegfx::B2DPolyPolygon(basegfx::utils::createPolygonFromRect(basegfx::B2DRange(np0x, np0y, np1x, np1y)));
aB2DPoly.transform(getCurrentContext().Transformation);
// Clip against current clip path, if any
basegfx::B2DPolyPolygon aCurClip = getCurrentContext().Clip; if( aCurClip.count() ) {
aB2DPoly = basegfx::utils::clipPolyPolygonOnPolyPolygon( aB2DPoly, aCurClip, true, /* bInside, keep parts inside the clip */ false/* bStroke, filled not stroked */ );
} // TODO: That clipping might shift the fill pattern offsets
auto pPolyElement = ElementFactory::createPolyPolyElement(
m_pCurElement,
getGCId(getCurrentContext()),
aB2DPoly,
PATH_EOFILL, // Hmm how do I know if this should be EO or not?
nTile,
transformedxStep * aScale.getX(),
transformedyStep * -aScale.getY());
pPolyElement->updateGeometry();
pPolyElement->ZOrder = m_nNextZOrder++;
}
// We need to get a path that corresponds to a 'stroked path' - i.e. with whatever line // thickness etc is set. PolyPolygonStrokePrimitive2D::create2DDecomposition does most // of the work. const basegfx::BColor aBlack(0.0, 0.0, 0.0);
drawinglayer::attribute::LineAttribute aLineAttribute(aBlack, rGC.LineWidth * nScale,
rGC.LineJoin);
rtl::Reference<drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D> aStrokePrimitive( new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(aNewClip, aLineAttribute));
drawinglayer::primitive2d::Primitive2DContainer aPrimitiveContainer; const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
aStrokePrimitive->get2DDecomposition(aPrimitiveContainer, aViewInformation2D);
// Based on extractLineContourFromPrimitive2DSequence and ImpConvertToContourObj
drawinglayer::processor2d::LineGeometryExtractor2D aExtractor(aViewInformation2D);
aExtractor.process(aPrimitiveContainer);
basegfx::B2DPolygonVector aHairlines = aExtractor.getExtractedHairlines(); auto aFills = aExtractor.getExtractedLineFills();
staticbool lr_tb_sort( std::unique_ptr<Element> const & pLeft, std::unique_ptr<Element> const & pRight )
{ // Ensure irreflexivity (which could be compromised if h or w is negative): if (pLeft == pRight) returnfalse;
// first: top-bottom sorting
// Note: allow for 10% overlap on text lines since text lines are usually // of the same order as font height whereas the real paint area // of text is usually smaller double fudge_factor_left = 0.0, fudge_factor_right = 0.0; if( pLeft->dynCastAsTextElement() )
fudge_factor_left = 0.1; if( pRight->dynCastAsTextElement() )
fudge_factor_right = 0.1;
// Allow negative height double lower_boundary_left = pLeft->y + std::max(pLeft->h, 0.0) - fabs(pLeft->h) * fudge_factor_left; double lower_boundary_right = pRight->y + std::max(pRight->h, 0.0) - fabs(pRight->h) * fudge_factor_right; double upper_boundary_left = pLeft->y + std::min(pLeft->h, 0.0); double upper_boundary_right = pRight->y + std::min(pRight->h, 0.0); // if left's lower boundary is above right's upper boundary // then left is smaller if( lower_boundary_left < upper_boundary_right ) returntrue; // if right's lower boundary is above left's upper boundary // then left is definitely not smaller if( lower_boundary_right < upper_boundary_left ) returnfalse;
// Allow negative width double left_boundary_left = pLeft->y + std::min(pLeft->w, 0.0); double left_boundary_right = pRight->y + std::min(pRight->w, 0.0); double right_boundary_left = pLeft->y + std::max(pLeft->w, 0.0); double right_boundary_right = pRight->y + std::max(pRight->w, 0.0); // by now we have established that left and right are inside // a "line", that is they have vertical overlap // second: left-right sorting // if left's right boundary is left to right's left boundary // then left is smaller if( right_boundary_left < left_boundary_right ) returntrue; // if right's right boundary is left to left's left boundary // then left is definitely not smaller if( right_boundary_right < left_boundary_left ) returnfalse;
// here we have established vertical and horizontal overlap // so sort left first, top second if( pLeft->x < pRight->x ) returntrue; if( pRight->x < pLeft->x ) returnfalse; if( pLeft->y < pRight->y ) returntrue;
// sort method from std::list is equivalent to stable_sort // See S Meyers, Effective STL
pEle->Children.sort(lr_tb_sort);
}
/* Produce mirrored-image for each code point which has the Bidi_Mirrored property, within a string. This need to be done in forward order.
*/
OUString PDFIProcessor::SubstituteBidiMirrored(std::u16string_view rString)
{ const sal_Int32 nLen = rString.size();
OUStringBuffer aMirror(nLen);
for (sal_Int32 i = 0; i < nLen;) { const sal_uInt32 nCodePoint = o3tl::iterateCodePoints(rString, &i);
aMirror.appendUtf32(unicode::GetMirroredChar(nCodePoint));
} return aMirror.makeStringAndClear();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.