/src/libreoffice/vcl/source/outdev/EmphasisMarks.cxx
Line | Count | Source |
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 <sal/config.h> |
21 | | #include <vcl/outdev.hxx> |
22 | | #include <font/EmphasisMark.hxx> |
23 | | #include <impglyphitem.hxx> |
24 | | #include <vcl/vcllayout.hxx> |
25 | | |
26 | | void OutputDevice::createEmphasisMarks( |
27 | | FontEmphasisMark nEmphasisMark, tools::Long nEmphasisHeight, const SalLayout& rSalLayout, |
28 | | const std::function<void(const basegfx::B2DPoint&, const basegfx::B2DPolyPolygon&, bool, |
29 | | const tools::Rectangle&, const tools::Rectangle&)>& rCallback) const |
30 | 0 | { |
31 | | // tooling method to create geometry data for EmphasisMarks. It does the same |
32 | | // as OutputDevice::ImplDrawEmphasisMarks, but feeds the data into the |
33 | | // callback for further usage |
34 | 0 | vcl::font::EmphasisMark aEmphasisMark(nEmphasisMark, nEmphasisHeight, GetDPIY()); |
35 | |
|
36 | 0 | Point aOffset(0, 0); |
37 | 0 | Point aOffsetVert(0, 0); |
38 | |
|
39 | 0 | if (nEmphasisMark & FontEmphasisMark::PosBelow) |
40 | 0 | { |
41 | 0 | aOffset.AdjustY(mpFontInstance->mxFontMetric->GetDescent() + aEmphasisMark.GetYOffset()); |
42 | 0 | aOffsetVert = aOffset; |
43 | 0 | } |
44 | 0 | else |
45 | 0 | { |
46 | 0 | aOffset.AdjustY(-(mpFontInstance->mxFontMetric->GetAscent() + aEmphasisMark.GetYOffset())); |
47 | | // Todo: use ideographic em-box or ideographic character face information. |
48 | 0 | aOffsetVert.AdjustY(-(mpFontInstance->mxFontMetric->GetAscent() |
49 | 0 | + mpFontInstance->mxFontMetric->GetDescent() |
50 | 0 | + aEmphasisMark.GetYOffset())); |
51 | 0 | } |
52 | |
|
53 | 0 | tools::Long nEmphasisWidth2 = aEmphasisMark.GetWidth() / 2; |
54 | 0 | tools::Long nEmphasisHeight2 = nEmphasisHeight / 2; |
55 | 0 | aOffset += Point(nEmphasisWidth2, nEmphasisHeight2); |
56 | |
|
57 | 0 | basegfx::B2DPolyPolygon aShape(aEmphasisMark.GetShape().getB2DPolyPolygon()); |
58 | |
|
59 | 0 | basegfx::B2DPoint aOutPoint; |
60 | 0 | basegfx::B2DRectangle aRectangle; |
61 | 0 | const GlyphItem* pGlyph; |
62 | 0 | const LogicalFontInstance* pGlyphFont; |
63 | 0 | int nStart = 0; |
64 | 0 | while (rSalLayout.GetNextGlyph(&pGlyph, aOutPoint, nStart, &pGlyphFont)) |
65 | 0 | { |
66 | 0 | if (!pGlyph->GetGlyphBoundRect(pGlyphFont, aRectangle)) |
67 | 0 | continue; |
68 | | |
69 | 0 | if (!pGlyph->IsSpacing()) |
70 | 0 | { |
71 | 0 | Point aAdjPoint; |
72 | 0 | if (pGlyph->IsVertical()) |
73 | 0 | { |
74 | 0 | aAdjPoint = aOffsetVert; |
75 | 0 | aAdjPoint.AdjustX((-pGlyph->origWidth() + aEmphasisMark.GetWidth()) / 2); |
76 | 0 | } |
77 | 0 | else |
78 | 0 | { |
79 | 0 | aAdjPoint = aOffset; |
80 | 0 | aAdjPoint.AdjustX(aRectangle.getMinX() |
81 | 0 | + (aRectangle.getWidth() - aEmphasisMark.GetWidth()) / 2); |
82 | 0 | } |
83 | |
|
84 | 0 | if (mpFontInstance->mnOrientation) |
85 | 0 | { |
86 | 0 | Point aOriginPt(0, 0); |
87 | 0 | aOriginPt.RotateAround(aAdjPoint, mpFontInstance->mnOrientation); |
88 | 0 | } |
89 | 0 | aOutPoint.adjustX(aAdjPoint.X() - nEmphasisWidth2); |
90 | 0 | aOutPoint.adjustY(aAdjPoint.Y() - nEmphasisHeight2); |
91 | | |
92 | | // use callback to propagate the data to where it was requested from |
93 | 0 | rCallback(aOutPoint, aShape, aEmphasisMark.IsShapePolyLine(), aEmphasisMark.GetRect1(), |
94 | 0 | aEmphasisMark.GetRect2()); |
95 | 0 | } |
96 | 0 | } |
97 | 0 | } |
98 | | |
99 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |