LibreOffice Module filter (master) 1
bundles.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 "bundles.hxx"
22
23#include <string.h>
24
25void Bundle::SetColor( sal_uInt32 nColor )
26{
27 mnColor = nColor;
28}
29
31 : nFontNameCount(0)
32 , nCharSetCount(0)
33{
34}
35
36FontEntry* CGMFList::GetFontEntry( sal_uInt32 nIndex )
37{
38 sal_uInt32 nInd = nIndex;
39 if ( nInd )
40 nInd--;
41 return ( nInd < aFontEntryList.size() ) ? &aFontEntryList[nInd] : nullptr;
42}
43
44static sal_Int8* ImplSearchEntry( sal_Int8* pSource, sal_Int8 const * pDest, sal_uInt32 nComp, sal_uInt32 nSize )
45{
46 while ( nComp-- >= nSize )
47 {
48 sal_uInt32 i;
49 for ( i = 0; i < nSize; i++ )
50 {
51 if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) )
52 break;
53 }
54 if ( i == nSize )
55 return pSource;
56 pSource++;
57 }
58 return nullptr;
59}
60
61void CGMFList::InsertName( sal_uInt8 const * pSource, sal_uInt32 nSize )
62{
63 FontEntry* pFontEntry;
64 if (nFontNameCount == aFontEntryList.size())
65 {
66 aFontEntryList.push_back(FontEntry());
67 pFontEntry = &aFontEntryList.back();
68 }
69 else
70 {
71 pFontEntry = &aFontEntryList[nFontNameCount];
72 }
74
75 if (nSize == 0)
76 return;
77
78 std::vector<sal_Int8> aBuf(pSource, pSource + nSize);
79 sal_Int8* pFound = ImplSearchEntry(aBuf.data(), reinterpret_cast<sal_Int8 const *>("ITALIC"), nSize, 6);
80 if (pFound)
81 {
82 pFontEntry->nFontType |= 1;
83 sal_uInt32 nPrev = pFound - aBuf.data();
84 sal_uInt32 nToCopyOfs = 6;
85 if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
86 {
87 nPrev--;
88 pFound--;
89 nToCopyOfs++;
90 }
91 sal_uInt32 nToCopy = nSize - nToCopyOfs - nPrev;
92 if ( nToCopy )
93 {
94 memmove( pFound, pFound + nToCopyOfs, nToCopy );
95 }
96 nSize -= nToCopyOfs;
97 }
98 pFound = ImplSearchEntry(aBuf.data(), reinterpret_cast<sal_Int8 const *>("BOLD"), nSize, 4);
99 if ( pFound )
100 {
101 pFontEntry->nFontType |= 2;
102
103 sal_uInt32 nPrev = pFound - aBuf.data();
104 sal_uInt32 nToCopyOfs = 4;
105 if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
106 {
107 nPrev--;
108 pFound--;
109 nToCopyOfs++;
110 }
111 sal_uInt32 nToCopy = nSize - nToCopyOfs - nPrev;
112 if ( nToCopy )
113 {
114 memmove( pFound, pFound + nToCopyOfs, nToCopy );
115 }
116 nSize -= nToCopyOfs;
117 }
118 pFontEntry->aFontName.assign(aBuf.data(), aBuf.data() + nSize);
119}
120
121void CGMFList::InsertCharSet( sal_uInt8 const * pSource, sal_uInt32 nSize )
122{
123 FontEntry* pFontEntry;
124 if (nCharSetCount == aFontEntryList.size())
125 {
126 aFontEntryList.push_back(FontEntry());
127 pFontEntry = &aFontEntryList.back();
128 }
129 else
130 {
131 pFontEntry = &aFontEntryList[nCharSetCount];
132 }
134
135 if (nSize == 0)
136 return;
137
138 pFontEntry->aCharSetValue.assign(pSource, pSource + nSize);
139}
140
141/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static sal_Int8 * ImplSearchEntry(sal_Int8 *pSource, sal_Int8 const *pDest, sal_uInt32 nComp, sal_uInt32 nSize)
Definition: bundles.cxx:44
sal_uInt32 mnColor
Definition: bundles.hxx:32
void SetColor(sal_uInt32 nColor)
Definition: bundles.cxx:25
void InsertCharSet(sal_uInt8 const *pSource, sal_uInt32 nSize)
Definition: bundles.cxx:121
CGMFList()
Definition: bundles.cxx:30
sal_uInt32 nFontNameCount
Definition: bundles.hxx:154
FontEntry * GetFontEntry(sal_uInt32)
Definition: bundles.cxx:36
sal_uInt32 nCharSetCount
Definition: bundles.hxx:155
std::vector< FontEntry > aFontEntryList
Definition: bundles.hxx:156
void InsertName(sal_uInt8 const *pSource, sal_uInt32 nSize)
Definition: bundles.cxx:61
sal_Int32 nIndex
aBuf
int i
Definition: gentoken.py:48
std::vector< sal_Int8 > aFontName
Definition: bundles.hxx:142
std::vector< sal_Int8 > aCharSetValue
Definition: bundles.hxx:143
sal_uInt32 nFontType
Definition: bundles.hxx:144
unsigned char sal_uInt8
signed char sal_Int8