LibreOffice Module svtools (master) 1
ctrltool.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 <sal/config.h>
21
22#include <memory>
23#include <string.h>
24#include <string_view>
25
26#include <tools/debug.hxx>
29#include <utility>
30#include <vcl/outdev.hxx>
31#include <vcl/svapp.hxx>
32#include <vcl/settings.hxx>
33#include <sal/macros.h>
34#include <svtools/strings.hrc>
35#include <svtools/svtresid.hxx>
36#include <svtools/ctrltool.hxx>
38#include <o3tl/string_view.hxx>
39#include <comphelper/lok.hxx>
40
41// Standard fontsizes for scalable Fonts
42const int FontList::aStdSizeAry[] =
43{
44 60,
45 70,
46 80,
47 90,
48 100,
49 105,
50 110,
51 120,
52 130,
53 140,
54 150,
55 160,
56 180,
57 200,
58 210,
59 220,
60 240,
61 260,
62 280,
63 320,
64 360,
65 400,
66 420,
67 440,
68 480,
69 540,
70 600,
71 660,
72 720,
73 800,
74 880,
75 960,
76 0
77};
78
79namespace {
80
81class ImplFontListFontMetric : public FontMetric
82{
83 friend FontList;
84
85private:
86 ImplFontListFontMetric* mpNext;
87
88public:
89 ImplFontListFontMetric( const FontMetric& rInfo ) :
90 FontMetric( rInfo ), mpNext(nullptr)
91 {
92 }
93
94};
95
96enum class FontListFontNameType
97{
98 NONE = 0x00,
99 PRINTER = 0x01,
100 SCREEN = 0x02,
101};
102
103}
104namespace o3tl
105{
106 template<> struct typed_flags<FontListFontNameType> : is_typed_flags<FontListFontNameType, 0x3> {};
107}
108
110{
111 friend class FontList;
112
113private:
114 OUString maSearchName;
115 ImplFontListFontMetric* mpFirst;
116 FontListFontNameType mnType;
117
118 explicit ImplFontListNameInfo(OUString aSearchName)
119 : maSearchName(std::move(aSearchName))
120 , mpFirst(nullptr)
121 , mnType(FontListFontNameType::NONE)
122 {
123 }
124};
125
126//sort normal to the start
127static int sortWeightValue(FontWeight eWeight)
128{
129 if (eWeight < WEIGHT_NORMAL)
130 return eWeight + 1;
131 if (eWeight > WEIGHT_NORMAL)
132 return eWeight - 1;
133 return 0; // eWeight == WEIGHT_NORMAL
134}
135
136static sal_Int32 ImplCompareFontMetric( ImplFontListFontMetric* pInfo1,
137 ImplFontListFontMetric* pInfo2 )
138{
139 //Sort non italic before italics
140 if ( pInfo1->GetItalic() < pInfo2->GetItalic() )
141 return -1;
142 else if ( pInfo1->GetItalic() > pInfo2->GetItalic() )
143 return 1;
144
145 //Sort normal weight to the start, followed by lightest to heaviest weights
146 int nWeight1 = sortWeightValue(pInfo1->GetWeight());
147 int nWeight2 = sortWeightValue(pInfo2->GetWeight());
148
149 if ( nWeight1 < nWeight2 )
150 return -1;
151 else if ( nWeight1 > nWeight2 )
152 return 1;
153
154 return pInfo1->GetStyleName().compareTo( pInfo2->GetStyleName() );
155}
156
157static OUString ImplMakeSearchString(const OUString& rStr)
158{
159 return rStr.toAsciiLowerCase();
160}
161
162static OUString ImplMakeSearchStringFromName(std::u16string_view rStr)
163{
164 // check for features before alternate font separator
165 if (size_t nColon = rStr.find(':'); nColon != std::u16string_view::npos)
166 if (size_t nSemiColon = rStr.find(';'); nSemiColon == std::u16string_view::npos || nColon < nSemiColon)
167 return ImplMakeSearchString(OUString(o3tl::getToken(rStr, 0, ':' )));
168 return ImplMakeSearchString(OUString(o3tl::getToken(rStr, 0, ';' )));
169}
170
171ImplFontListNameInfo* FontList::ImplFind(std::u16string_view rSearchName, sal_uInt32* pIndex) const
172{
173 // Append if there is no entry in the list or if the entry is larger
174 // then the last one. We only compare to the last entry as the list of VCL
175 // is returned sorted, which increases the probability that appending
176 // is more likely
177 if (m_Entries.empty())
178 {
179 if ( pIndex )
180 *pIndex = SAL_MAX_UINT32;
181 return nullptr;
182 }
183 else
184 {
185 const ImplFontListNameInfo* pCmpData = m_Entries.back().get();
186 sal_Int32 nComp = rSearchName.compare( pCmpData->maSearchName );
187 if (nComp > 0)
188 {
189 if ( pIndex )
190 *pIndex = SAL_MAX_UINT32;
191 return nullptr;
192 }
193 else if (nComp == 0)
194 return const_cast<ImplFontListNameInfo*>(pCmpData);
195 }
196
197 // search fonts in the list
198 const ImplFontListNameInfo* pCompareData;
199 const ImplFontListNameInfo* pFoundData = nullptr;
200 size_t nLow = 0;
201 size_t nHigh = m_Entries.size() - 1;
202 size_t nMid;
203
204 do
205 {
206 nMid = (nLow + nHigh) / 2;
207 pCompareData = m_Entries[nMid].get();
208 sal_Int32 nComp = rSearchName.compare(pCompareData->maSearchName);
209 if (nComp < 0)
210 {
211 if ( !nMid )
212 break;
213 nHigh = nMid-1;
214 }
215 else
216 {
217 if (nComp > 0)
218 nLow = nMid + 1;
219 else
220 {
221 pFoundData = pCompareData;
222 break;
223 }
224 }
225 }
226 while ( nLow <= nHigh );
227
228 if ( pIndex )
229 {
230 sal_Int32 nComp = rSearchName.compare(pCompareData->maSearchName);
231 if (nComp > 0)
232 *pIndex = (nMid+1);
233 else
234 *pIndex = nMid;
235 }
236
237 return const_cast<ImplFontListNameInfo*>(pFoundData);
238}
239
240ImplFontListNameInfo* FontList::ImplFindByName(std::u16string_view rStr) const
241{
242 OUString aSearchName = ImplMakeSearchStringFromName(rStr);
243 return ImplFind( aSearchName, nullptr );
244}
245
246void FontList::ImplInsertFonts(OutputDevice* pDevice, bool bInsertData)
247{
248 rtl_TextEncoding eSystemEncoding = osl_getThreadTextEncoding();
249
250 FontListFontNameType nType;
251 if ( pDevice->GetOutDevType() != OUTDEV_PRINTER )
252 nType = FontListFontNameType::SCREEN;
253 else
254 nType = FontListFontNameType::PRINTER;
255
256 // inquire all fonts from the device
257 int n = pDevice->GetFontFaceCollectionCount();
259 {
260 pDevice->RefreshFontData(true);
261 n = pDevice->GetFontFaceCollectionCount();
262 }
263
264 for (int i = 0; i < n; ++i)
265 {
266 FontMetric aFontMetric = pDevice->GetFontMetricFromCollection( i );
267 OUString aSearchName(aFontMetric.GetFamilyName());
269 sal_uInt32 nIndex;
270 aSearchName = ImplMakeSearchString(aSearchName);
271 pData = ImplFind( aSearchName, &nIndex );
272
273 if ( !pData )
274 {
275 if ( bInsertData )
276 {
277 ImplFontListFontMetric* pNewInfo = new ImplFontListFontMetric( aFontMetric );
278 pData = new ImplFontListNameInfo( aSearchName );
279 pData->mpFirst = pNewInfo;
280 pNewInfo->mpNext = nullptr;
281
282 if (nIndex < static_cast<sal_uInt32>(m_Entries.size()))
283 m_Entries.insert(m_Entries.begin()+nIndex,
284 std::unique_ptr<ImplFontListNameInfo>(pData));
285 else
286 m_Entries.push_back(std::unique_ptr<ImplFontListNameInfo>(pData));
287 }
288 }
289 else
290 {
291 if ( bInsertData )
292 {
293 bool bInsert = true;
294 ImplFontListFontMetric* pPrev = nullptr;
295 ImplFontListFontMetric* pTemp = pData->mpFirst;
296 ImplFontListFontMetric* pNewInfo = new ImplFontListFontMetric( aFontMetric );
297 while ( pTemp )
298 {
299 sal_Int32 eComp = ImplCompareFontMetric( pNewInfo, pTemp );
300 if ( eComp <= 0 )
301 {
302 if ( eComp == 0 )
303 {
304 // Overwrite charset, because charset should match
305 // with the system charset
306 if ( (pTemp->GetCharSet() != eSystemEncoding) &&
307 (pNewInfo->GetCharSet() == eSystemEncoding) )
308 {
309 ImplFontListFontMetric* pTemp2 = pTemp->mpNext;
310 *static_cast<FontMetric*>(pTemp) = *static_cast<FontMetric*>(pNewInfo);
311 pTemp->mpNext = pTemp2;
312 }
313 delete pNewInfo;
314 bInsert = false;
315 }
316
317 break;
318 }
319
320 pPrev = pTemp;
321 pTemp = pTemp->mpNext;
322 }
323
324 if ( bInsert )
325 {
326 pNewInfo->mpNext = pTemp;
327 if ( pPrev )
328 pPrev->mpNext = pNewInfo;
329 else
330 pData->mpFirst = pNewInfo;
331 }
332 }
333 }
334
335 if ( pData )
336 pData->mnType |= nType;
337 }
338}
339
341{
342 // initialise variables
343 mpDev = pDevice;
344 mpDev2 = pDevice2;
345
346 // store style names
347 maLight = SvtResId(STR_SVT_STYLE_LIGHT);
348 maLightItalic = SvtResId(STR_SVT_STYLE_LIGHT_ITALIC);
349 maNormal = SvtResId(STR_SVT_STYLE_NORMAL);
350 maNormalItalic = SvtResId(STR_SVT_STYLE_NORMAL_ITALIC);
351 maBold = SvtResId(STR_SVT_STYLE_BOLD);
352 maBoldItalic = SvtResId(STR_SVT_STYLE_BOLD_ITALIC);
353 maBlack = SvtResId(STR_SVT_STYLE_BLACK);
354 maBlackItalic = SvtResId(STR_SVT_STYLE_BLACK_ITALIC);
355
356 ImplInsertFonts(pDevice, true);
357
358 // if required compare to the screen fonts
359 // in order to map the duplicates to Equal
360 bool bCompareWindow = false;
361 if ( !pDevice2 && (pDevice->GetOutDevType() == OUTDEV_PRINTER) )
362 {
363 bCompareWindow = true;
365 }
366
367 if ( pDevice2 &&
368 (pDevice2->GetOutDevType() != pDevice->GetOutDevType()) )
369 ImplInsertFonts(pDevice2, !bCompareWindow);
370}
371
373{
374 // delete FontMetrics
375 ImplFontListFontMetric *pTemp, *pInfo;
376 for (auto const& it : m_Entries)
377 {
378 pInfo = it->mpFirst;
379 while ( pInfo )
380 {
381 pTemp = pInfo->mpNext;
382 delete pInfo;
383 pInfo = pTemp;
384 }
385 }
386}
387
388std::unique_ptr<FontList> FontList::Clone() const
389{
390 return std::unique_ptr<FontList>(new FontList(mpDev, mpDev2));
391}
392
393const OUString& FontList::GetStyleName(FontWeight eWeight, FontItalic eItalic) const
394{
395 if ( eWeight > WEIGHT_BOLD )
396 {
397 if ( eItalic > ITALIC_NONE )
398 return maBlackItalic;
399 else
400 return maBlack;
401 }
402 else if ( eWeight > WEIGHT_MEDIUM )
403 {
404 if ( eItalic > ITALIC_NONE )
405 return maBoldItalic;
406 else
407 return maBold;
408 }
409 else if ( eWeight > WEIGHT_LIGHT )
410 {
411 if ( eItalic > ITALIC_NONE )
412 return maNormalItalic;
413 else
414 return maNormal;
415 }
416 else if ( eWeight != WEIGHT_DONTKNOW )
417 {
418 if ( eItalic > ITALIC_NONE )
419 return maLightItalic;
420 else
421 return maLight;
422 }
423 else
424 {
425 if ( eItalic > ITALIC_NONE )
426 return maNormalItalic;
427 else
428 return maNormal;
429 }
430}
431
432OUString FontList::GetStyleName(const FontMetric& rInfo) const
433{
434 OUString aStyleName = rInfo.GetStyleName();
435 FontWeight eWeight = rInfo.GetWeight();
436 FontItalic eItalic = rInfo.GetItalic();
437
438 // return synthetic Name if no StyleName was set
439 if (aStyleName.isEmpty())
440 aStyleName = GetStyleName(eWeight, eItalic);
441 else
442 {
443 // Translate StyleName to localized name
444 OUString aCompareStyleName = aStyleName.toAsciiLowerCase().replaceAll(" ", "");
445 if (aCompareStyleName == "bold")
446 aStyleName = maBold;
447 else if (aCompareStyleName == "bolditalic")
448 aStyleName = maBoldItalic;
449 else if (aCompareStyleName == "italic")
450 aStyleName = maNormalItalic;
451 else if (aCompareStyleName == "standard")
452 aStyleName = maNormal;
453 else if (aCompareStyleName == "regular")
454 aStyleName = maNormal;
455 else if (aCompareStyleName == "light")
456 aStyleName = maLight;
457 else if (aCompareStyleName == "lightitalic")
458 aStyleName = maLightItalic;
459 else if (aCompareStyleName == "black")
460 aStyleName = maBlack;
461 else if (aCompareStyleName == "blackitalic")
462 aStyleName = maBlackItalic;
463 /* tdf#107700 support some less common style names with localization */
464 else if (aCompareStyleName == "book")
465 aStyleName = SvtResId(STR_SVT_STYLE_BOOK);
466 else if (aCompareStyleName == "boldoblique")
467 aStyleName = SvtResId(STR_SVT_STYLE_BOLD_OBLIQUE);
468 else if (aCompareStyleName == "condensed")
469 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED);
470 else if (aCompareStyleName == "condensedbold")
471 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED_BOLD);
472 else if (aCompareStyleName == "condensedbolditalic")
473 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED_BOLD_ITALIC);
474 else if (aCompareStyleName == "condensedboldoblique")
475 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED_BOLD_OBLIQUE);
476 else if (aCompareStyleName == "condenseditalic")
477 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED_ITALIC);
478 else if (aCompareStyleName == "condensedoblique")
479 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED_OBLIQUE);
480 else if (aCompareStyleName == "extralight")
481 aStyleName = SvtResId(STR_SVT_STYLE_EXTRALIGHT);
482 else if (aCompareStyleName == "extralightitalic")
483 aStyleName = SvtResId(STR_SVT_STYLE_EXTRALIGHT_ITALIC);
484 else if (aCompareStyleName == "oblique")
485 aStyleName = SvtResId(STR_SVT_STYLE_OBLIQUE);
486 else if (aCompareStyleName == "semibold")
487 aStyleName = SvtResId(STR_SVT_STYLE_SEMIBOLD);
488 else if (aCompareStyleName == "semibolditalic")
489 aStyleName = SvtResId(STR_SVT_STYLE_SEMIBOLD_ITALIC);
490 // tdf#147739 medium is not a synonym of normal
491 else if (aCompareStyleName == "medium")
492 aStyleName = SvtResId(STR_SVT_STYLE_MEDIUM);
493 else if (aCompareStyleName == "mediumitalic")
494 aStyleName = SvtResId(STR_SVT_STYLE_MEDIUM_ITALIC);
495
496 // fix up StyleName, because the PS Printer driver from
497 // W2000 returns wrong StyleNames (e.g. Bold instead of Bold Italic
498 // for Helvetica)
499 if ( eItalic > ITALIC_NONE )
500 {
501 if ( (aStyleName == maNormal) ||
502 (aStyleName == maBold) ||
503 (aStyleName == maLight) ||
504 (aStyleName == maBlack) )
505 aStyleName = GetStyleName( eWeight, eItalic );
506 }
507 }
508
509 return aStyleName;
510}
511
512OUString FontList::GetFontMapText( const FontMetric& rInfo ) const
513{
514 if ( rInfo.GetFamilyName().isEmpty() )
515 {
516 return OUString();
517 }
518
519 // Search Fontname
521 if ( !pData )
522 {
523 if (maMapNotAvailable.isEmpty())
524 maMapNotAvailable = SvtResId(STR_SVT_FONTMAP_NOTAVAILABLE);
525 return maMapNotAvailable;
526 }
527
528 // search for synthetic style
529 FontListFontNameType nType = pData->mnType;
530 const OUString& rStyleName = rInfo.GetStyleName();
531 if (!rStyleName.isEmpty())
532 {
533 bool bNotSynthetic = false;
534 FontWeight eWeight = rInfo.GetWeight();
535 FontItalic eItalic = rInfo.GetItalic();
536 ImplFontListFontMetric* pFontMetric = pData->mpFirst;
537 while ( pFontMetric )
538 {
539 if ( (eWeight == pFontMetric->GetWeight()) &&
540 (eItalic == pFontMetric->GetItalic()) )
541 {
542 bNotSynthetic = true;
543 break;
544 }
545
546 pFontMetric = pFontMetric->mpNext;
547 }
548
549 if ( !bNotSynthetic )
550 {
551 if (maMapStyleNotAvailable.isEmpty())
552 const_cast<FontList*>(this)->maMapStyleNotAvailable = SvtResId(STR_SVT_FONTMAP_STYLENOTAVAILABLE);
554 }
555 }
556
557 // Only Printer-Font?
558 if ( nType == FontListFontNameType::PRINTER )
559 {
560 if (maMapPrinterOnly.isEmpty())
561 const_cast<FontList*>(this)->maMapPrinterOnly = SvtResId(STR_SVT_FONTMAP_PRINTERONLY);
562 return maMapPrinterOnly;
563 }
564 else
565 {
566 if (maMapBoth.isEmpty())
567 const_cast<FontList*>(this)->maMapBoth = SvtResId(STR_SVT_FONTMAP_BOTH);
568 return maMapBoth;
569 }
570}
571
572namespace
573{
574 FontMetric makeMissing(ImplFontListFontMetric const * pFontNameInfo, std::u16string_view rName,
575 FontWeight eWeight, FontItalic eItalic)
576 {
577 FontMetric aInfo;
578 // if the fontname matches, we copy as much as possible
579 if (pFontNameInfo)
580 {
581 aInfo = *pFontNameInfo;
582 aInfo.SetStyleName(OUString());
583 }
584
585 aInfo.SetWeight(eWeight);
586 aInfo.SetItalic(eItalic);
587
588 //If this is a known but uninstalled symbol font which we can remap to
589 //OpenSymbol then toggle its charset to be a symbol font
590 if (ConvertChar::GetRecodeData(rName, u"OpenSymbol"))
591 aInfo.SetCharSet(RTL_TEXTENCODING_SYMBOL);
592
593 return aInfo;
594 }
595}
596
597FontMetric FontList::Get(const OUString& rName, const OUString& rStyleName) const
598{
600 ImplFontListFontMetric* pFontMetric = nullptr;
601 ImplFontListFontMetric* pFontNameInfo = nullptr;
602 if ( pData )
603 {
604 ImplFontListFontMetric* pSearchInfo = pData->mpFirst;
605 pFontNameInfo = pSearchInfo;
606 pSearchInfo = pData->mpFirst;
607 while ( pSearchInfo )
608 {
609 if (rStyleName.equalsIgnoreAsciiCase(GetStyleName(*pSearchInfo)))
610 {
611 pFontMetric = pSearchInfo;
612 break;
613 }
614
615 pSearchInfo = pSearchInfo->mpNext;
616 }
617 }
618
619 // reproduce attributes if data could not be found
620 FontMetric aInfo;
621 if ( !pFontMetric )
622 {
623 FontWeight eWeight = WEIGHT_DONTKNOW;
624 FontItalic eItalic = ITALIC_NONE;
625
626 if ( rStyleName == maNormal )
627 {
628 eItalic = ITALIC_NONE;
629 eWeight = WEIGHT_NORMAL;
630 }
631 else if ( rStyleName == maNormalItalic )
632 {
633 eItalic = ITALIC_NORMAL;
634 eWeight = WEIGHT_NORMAL;
635 }
636 else if ( rStyleName == maBold )
637 {
638 eItalic = ITALIC_NONE;
639 eWeight = WEIGHT_BOLD;
640 }
641 else if ( rStyleName == maBoldItalic )
642 {
643 eItalic = ITALIC_NORMAL;
644 eWeight = WEIGHT_BOLD;
645 }
646 else if ( rStyleName == maLight )
647 {
648 eItalic = ITALIC_NONE;
649 eWeight = WEIGHT_LIGHT;
650 }
651 else if ( rStyleName == maLightItalic )
652 {
653 eItalic = ITALIC_NORMAL;
654 eWeight = WEIGHT_LIGHT;
655 }
656 else if ( rStyleName == maBlack )
657 {
658 eItalic = ITALIC_NONE;
659 eWeight = WEIGHT_BLACK;
660 }
661 else if ( rStyleName == maBlackItalic )
662 {
663 eItalic = ITALIC_NORMAL;
664 eWeight = WEIGHT_BLACK;
665 }
666 aInfo = makeMissing(pFontNameInfo, rName, eWeight, eItalic);
667 }
668 else
669 aInfo = *pFontMetric;
670
671 // set Fontname to keep FontAlias
672 aInfo.SetFamilyName( rName );
673 aInfo.SetStyleName( rStyleName );
674
675 return aInfo;
676}
677
678FontMetric FontList::Get(const OUString& rName,
679 FontWeight eWeight, FontItalic eItalic) const
680{
682 ImplFontListFontMetric* pFontMetric = nullptr;
683 ImplFontListFontMetric* pFontNameInfo = nullptr;
684 if ( pData )
685 {
686 ImplFontListFontMetric* pSearchInfo = pData->mpFirst;
687 pFontNameInfo = pSearchInfo;
688 while ( pSearchInfo )
689 {
690 if ( (eWeight == pSearchInfo->GetWeight()) &&
691 (eItalic == pSearchInfo->GetItalic()) )
692 {
693 pFontMetric = pSearchInfo;
694 break;
695 }
696
697 pSearchInfo = pSearchInfo->mpNext;
698 }
699 }
700
701 // reproduce attributes if data could not be found
702 FontMetric aInfo;
703 if ( !pFontMetric )
704 aInfo = makeMissing(pFontNameInfo, rName, eWeight, eItalic);
705 else
706 aInfo = *pFontMetric;
707
708 // set Fontname to keep FontAlias
709 aInfo.SetFamilyName( rName );
710
711 return aInfo;
712}
713
714bool FontList::IsAvailable(std::u16string_view rName) const
715{
716 return (ImplFindByName( rName ) != nullptr);
717}
718
719const FontMetric& FontList::GetFontName(size_t const nFont) const
720{
721 DBG_ASSERT( nFont < GetFontNameCount(), "FontList::GetFontName(): nFont >= Count" );
722
723 return *(m_Entries[nFont]->mpFirst);
724}
725
726sal_Handle FontList::GetFirstFontMetric(std::u16string_view rName) const
727{
729 if ( !pData )
730 return nullptr;
731 else
732 return static_cast<sal_Handle>(pData->mpFirst);
733}
734
736{
737 ImplFontListFontMetric* pInfo = static_cast<ImplFontListFontMetric*>(hFontMetric);
738 return static_cast<sal_Handle>(pInfo->mpNext);
739}
740
742{
743 ImplFontListFontMetric* pInfo = static_cast<ImplFontListFontMetric*>(hFontMetric);
744 return *pInfo;
745}
746
748{
749 sal_Int32 mnSize;
750 const char* mszUtf8Name;
751};
752
754{
755 { 50, "\xe5\x85\xab\xe5\x8f\xb7" },
756 { 55, "\xe4\xb8\x83\xe5\x8f\xb7" },
757 { 65, "\xe5\xb0\x8f\xe5\x85\xad" },
758 { 75, "\xe5\x85\xad\xe5\x8f\xb7" },
759 { 90, "\xe5\xb0\x8f\xe4\xba\x94" },
760 { 105, "\xe4\xba\x94\xe5\x8f\xb7" },
761 { 120, "\xe5\xb0\x8f\xe5\x9b\x9b" },
762 { 140, "\xe5\x9b\x9b\xe5\x8f\xb7" },
763 { 150, "\xe5\xb0\x8f\xe4\xb8\x89" },
764 { 160, "\xe4\xb8\x89\xe5\x8f\xb7" },
765 { 180, "\xe5\xb0\x8f\xe4\xba\x8c" },
766 { 220, "\xe4\xba\x8c\xe5\x8f\xb7" },
767 { 240, "\xe5\xb0\x8f\xe4\xb8\x80" },
768 { 260, "\xe4\xb8\x80\xe5\x8f\xb7" },
769 { 360, "\xe5\xb0\x8f\xe5\x88\x9d" },
770 { 420, "\xe5\x88\x9d\xe5\x8f\xb7" }
771};
772
773FontSizeNames::FontSizeNames( LanguageType eLanguage )
774{
775 if ( eLanguage == LANGUAGE_DONTKNOW )
777 if ( eLanguage == LANGUAGE_SYSTEM )
779
780 if (MsLangId::isSimplifiedChinese(eLanguage))
781 {
782 // equivalent for traditional chinese disabled by popular request, #i89077#
785 }
786 else
787 {
788 mpArray = nullptr;
789 mnElem = 0;
790 }
791}
792
793sal_Int32 FontSizeNames::Name2Size( std::u16string_view rName ) const
794{
795 if ( mnElem )
796 {
797 OString aName(OUStringToOString(rName,
798 RTL_TEXTENCODING_UTF8));
799
800 // linear search is sufficient for this rare case
801 for( tools::Long i = mnElem; --i >= 0; )
802 if ( aName == mpArray[i].mszUtf8Name )
803 return mpArray[i].mnSize;
804 }
805
806 return 0;
807}
808
809OUString FontSizeNames::Size2Name( sal_Int32 nValue ) const
810{
811 OUString aStr;
812
813 // binary search
814 for( tools::Long lower = 0, upper = mnElem - 1; lower <= upper; )
815 {
816 tools::Long mid = (upper + lower) >> 1;
817 if ( nValue == mpArray[mid].mnSize )
818 {
819 aStr = OUString( mpArray[mid].mszUtf8Name, strlen(mpArray[mid].mszUtf8Name), RTL_TEXTENCODING_UTF8 );
820 break;
821 }
822 else if ( nValue < mpArray[mid].mnSize )
823 upper = mid - 1;
824 else /* ( nValue > mpArray[mid].mnSize ) */
825 lower = mid + 1;
826 }
827
828 return aStr;
829}
830
831OUString FontSizeNames::GetIndexName( sal_Int32 nIndex ) const
832{
833 OUString aStr;
834
835 if ( nIndex < mnElem )
836 aStr = OUString( mpArray[nIndex].mszUtf8Name, strlen(mpArray[nIndex].mszUtf8Name), RTL_TEXTENCODING_UTF8 );
837
838 return aStr;
839}
840
841sal_Int32 FontSizeNames::GetIndexSize( sal_Int32 nIndex ) const
842{
843 if ( nIndex >= mnElem )
844 return 0;
845 return mpArray[nIndex].mnSize;
846}
847
848/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
EdgeEntry * mpNext
SbxDimArrayRef mpArray
const LanguageTag & GetUILanguageTag() const
static OutputDevice * GetDefaultDevice()
static const AllSettings & GetSettings()
OUString GetFontMapText(const FontMetric &rFontMetric) const
Definition: ctrltool.cxx:512
OUString maBlack
Definition: ctrltool.hxx:145
std::unique_ptr< FontList > Clone() const
Definition: ctrltool.cxx:388
SVT_DLLPRIVATE ImplFontListNameInfo * ImplFindByName(std::u16string_view rStr) const
Definition: ctrltool.cxx:240
VclPtr< OutputDevice > mpDev
Definition: ctrltool.hxx:147
OUString maMapStyleNotAvailable
Definition: ctrltool.hxx:137
OUString maLight
Definition: ctrltool.hxx:139
OUString maMapBoth
Definition: ctrltool.hxx:135
OUString maBlackItalic
Definition: ctrltool.hxx:146
OUString maMapPrinterOnly
Definition: ctrltool.hxx:136
FontMetric Get(const OUString &rName, const OUString &rStyleName) const
Definition: ctrltool.cxx:597
size_t GetFontNameCount() const
Definition: ctrltool.hxx:178
static sal_Handle GetNextFontMetric(sal_Handle hFontMetric)
Definition: ctrltool.cxx:735
OUString maNormalItalic
Definition: ctrltool.hxx:142
SVT_DLLPRIVATE ImplFontListNameInfo * ImplFind(std::u16string_view rSearchName, sal_uInt32 *pIndex) const
Definition: ctrltool.cxx:171
static const FontMetric & GetFontMetric(sal_Handle hFontMetric)
Definition: ctrltool.cxx:741
std::vector< std::unique_ptr< ImplFontListNameInfo > > m_Entries
Definition: ctrltool.hxx:149
OUString maNormal
Definition: ctrltool.hxx:141
OUString maBoldItalic
Definition: ctrltool.hxx:144
VclPtr< OutputDevice > mpDev2
Definition: ctrltool.hxx:148
SVT_DLLPRIVATE void ImplInsertFonts(OutputDevice *pDev, bool bInsertData)
Definition: ctrltool.cxx:246
static const int aStdSizeAry[]
Definition: ctrltool.hxx:133
OUString maMapNotAvailable
Definition: ctrltool.hxx:138
FontList(OutputDevice *pDevice, OutputDevice *pDevice2=nullptr)
Definition: ctrltool.cxx:340
bool IsAvailable(std::u16string_view rName) const
Definition: ctrltool.cxx:714
OUString maLightItalic
Definition: ctrltool.hxx:140
OUString maBold
Definition: ctrltool.hxx:143
sal_Handle GetFirstFontMetric(std::u16string_view rName) const
Definition: ctrltool.cxx:726
const OUString & GetStyleName(FontWeight eWeight, FontItalic eItalic) const
Definition: ctrltool.cxx:393
const FontMetric & GetFontName(size_t nFont) const
Definition: ctrltool.cxx:719
FontListFontNameType mnType
Definition: ctrltool.cxx:116
ImplFontListFontMetric * mpFirst
Definition: ctrltool.cxx:115
ImplFontListNameInfo(OUString aSearchName)
Definition: ctrltool.cxx:118
LanguageType getLanguageType(bool bResolveSystem=true) const
static LanguageType getConfiguredSystemUILanguage()
static bool isSimplifiedChinese(LanguageType nLang)
void RefreshFontData(const bool bNewFontLists)
int GetFontFaceCollectionCount() const
FontMetric GetFontMetricFromCollection(int nDevFontIndex) const
OutDevType GetOutDevType() const
void SetStyleName(const OUString &rStyleName)
const OUString & GetStyleName() const
FontItalic GetItalic()
void SetItalic(FontItalic)
void SetWeight(FontWeight)
const OUString & GetFamilyName() const
void SetCharSet(rtl_TextEncoding)
FontWeight GetWeight()
void SetFamilyName(const OUString &rFamilyName)
static sal_Int32 ImplCompareFontMetric(ImplFontListFontMetric *pInfo1, ImplFontListFontMetric *pInfo2)
Definition: ctrltool.cxx:136
static int sortWeightValue(FontWeight eWeight)
Definition: ctrltool.cxx:127
const ImplFSNameItem aImplSimplifiedChinese[]
Definition: ctrltool.cxx:753
static OUString ImplMakeSearchString(const OUString &rStr)
Definition: ctrltool.cxx:157
static OUString ImplMakeSearchStringFromName(std::u16string_view rStr)
Definition: ctrltool.cxx:162
#define DBG_ASSERT(sCon, aError)
FontItalic
ITALIC_NORMAL
ITALIC_NONE
WEIGHT_BOLD
WEIGHT_NORMAL
WEIGHT_LIGHT
WEIGHT_DONTKNOW
WEIGHT_MEDIUM
WEIGHT_BLACK
sal_Int32 nIndex
OUString aName
sal_Int64 n
#define SAL_N_ELEMENTS(arr)
aStr
std::unique_ptr< sal_Int32[]> pData
NONE
int i
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
FontWeight
long Long
OUTDEV_PRINTER
QPRO_FUNC_TYPE nType
const char * mszUtf8Name
Definition: ctrltool.cxx:750
sal_Int32 mnSize
Definition: ctrltool.cxx:749
OUString SvtResId(TranslateId aId)
Definition: svtresid.cxx:24
void * sal_Handle
#define SAL_MAX_UINT32