Update git submodules
[LibreOffice.git] / filter / source / graphicfilter / icgm / bundles.cxx
blob64e63a75018660877c276789502e41ff48fdb1f0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "bundles.hxx"
23 #include <string.h>
25 void Bundle::SetColor( sal_uInt32 nColor )
27 mnColor = nColor;
30 CGMFList::CGMFList()
31 : nFontNameCount(0)
32 , nCharSetCount(0)
36 FontEntry* CGMFList::GetFontEntry( sal_uInt32 nIndex )
38 sal_uInt32 nInd = nIndex;
39 if ( nInd )
40 nInd--;
41 return ( nInd < aFontEntryList.size() ) ? &aFontEntryList[nInd] : nullptr;
44 static sal_Int8* ImplSearchEntry( sal_Int8* pSource, sal_Int8 const * pDest, sal_uInt32 nComp, sal_uInt32 nSize )
46 while ( nComp-- >= nSize )
48 sal_uInt32 i;
49 for ( i = 0; i < nSize; i++ )
51 if ( ( pSource[i]&~0x20 ) != ( pDest[i]&~0x20 ) )
52 break;
54 if ( i == nSize )
55 return pSource;
56 pSource++;
58 return nullptr;
61 void CGMFList::InsertName( sal_uInt8 const * pSource, sal_uInt32 nSize )
63 FontEntry* pFontEntry;
64 if (nFontNameCount == aFontEntryList.size())
66 aFontEntryList.push_back(FontEntry());
67 pFontEntry = &aFontEntryList.back();
69 else
71 pFontEntry = &aFontEntryList[nFontNameCount];
73 nFontNameCount++;
75 if (nSize == 0)
76 return;
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)
82 pFontEntry->nFontType |= 1;
83 sal_uInt32 nPrev = pFound - aBuf.data();
84 sal_uInt32 nToCopyOfs = 6;
85 if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
87 nPrev--;
88 pFound--;
89 nToCopyOfs++;
91 sal_uInt32 nToCopy = nSize - nToCopyOfs - nPrev;
92 if ( nToCopy )
94 memmove( pFound, pFound + nToCopyOfs, nToCopy );
96 nSize -= nToCopyOfs;
98 pFound = ImplSearchEntry(aBuf.data(), reinterpret_cast<sal_Int8 const *>("BOLD"), nSize, 4);
99 if ( pFound )
101 pFontEntry->nFontType |= 2;
103 sal_uInt32 nPrev = pFound - aBuf.data();
104 sal_uInt32 nToCopyOfs = 4;
105 if ( nPrev && ( pFound[ -1 ] == '-' || pFound[ -1 ] == ' ' ) )
107 nPrev--;
108 pFound--;
109 nToCopyOfs++;
111 sal_uInt32 nToCopy = nSize - nToCopyOfs - nPrev;
112 if ( nToCopy )
114 memmove( pFound, pFound + nToCopyOfs, nToCopy );
116 nSize -= nToCopyOfs;
118 pFontEntry->aFontName.assign(aBuf.data(), aBuf.data() + nSize);
121 void CGMFList::InsertCharSet( sal_uInt8 const * pSource, sal_uInt32 nSize )
123 FontEntry* pFontEntry;
124 if (nCharSetCount == aFontEntryList.size())
126 aFontEntryList.push_back(FontEntry());
127 pFontEntry = &aFontEntryList.back();
129 else
131 pFontEntry = &aFontEntryList[nCharSetCount];
133 nCharSetCount++;
135 if (nSize == 0)
136 return;
138 pFontEntry->aCharSetValue.assign(pSource, pSource + nSize);
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */