2005-08-02 13:16:20 -04:00
|
|
|
/* ====================================================================
|
2006-12-22 14:18:16 -05:00
|
|
|
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
|
2005-08-02 13:16:20 -04:00
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
|
|
|
|
|
|
|
|
|
|
|
package org.apache.poi.hslf.record;
|
|
|
|
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647832 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r647824 | yegor | 2008-04-14 15:58:18 +0100 (Mon, 14 Apr 2008) | 1 line
make sure all hslf classes use POI loggers
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@647834 13f79535-47bb-0310-9956-ffa450edef68
2008-04-14 11:11:54 -04:00
|
|
|
import org.apache.poi.util.POILogger;
|
|
|
|
|
2005-08-02 13:16:20 -04:00
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <code>FontCollection</code> ia a container that holds information
|
|
|
|
* about all the fonts in the presentation.
|
|
|
|
*
|
|
|
|
* @author Yegor Kozlov
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class FontCollection extends RecordContainer {
|
|
|
|
private List fonts;
|
|
|
|
private byte[] _header;
|
|
|
|
|
|
|
|
protected FontCollection(byte[] source, int start, int len) {
|
|
|
|
// Grab the header
|
|
|
|
_header = new byte[8];
|
|
|
|
System.arraycopy(source,start,_header,0,8);
|
|
|
|
|
|
|
|
_children = Record.findChildRecords(source,start+8,len-8);
|
|
|
|
|
2006-05-09 06:47:22 -04:00
|
|
|
// Save font names into <code>List</code>
|
|
|
|
fonts = new ArrayList();
|
|
|
|
for (int i = 0; i < _children.length; i++){
|
|
|
|
if(_children[i] instanceof FontEntityAtom) {
|
|
|
|
FontEntityAtom atom = (FontEntityAtom)_children[i];
|
|
|
|
fonts.add(atom.getFontName());
|
|
|
|
} else {
|
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647832 via svnmerge from
https://svn.apache.org:443/repos/asf/poi/trunk
........
r647824 | yegor | 2008-04-14 15:58:18 +0100 (Mon, 14 Apr 2008) | 1 line
make sure all hslf classes use POI loggers
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@647834 13f79535-47bb-0310-9956-ffa450edef68
2008-04-14 11:11:54 -04:00
|
|
|
logger.log(POILogger.WARN, "Warning: FontCollection child wasn't a FontEntityAtom, was " + _children[i]);
|
2006-05-09 06:47:22 -04:00
|
|
|
}
|
|
|
|
}
|
2005-08-02 13:16:20 -04:00
|
|
|
}
|
|
|
|
|
2005-11-07 18:03:05 -05:00
|
|
|
/**
|
|
|
|
* Return the type, which is 2005
|
|
|
|
*/
|
2005-08-02 13:16:20 -04:00
|
|
|
public long getRecordType() {
|
|
|
|
return RecordTypes.FontCollection.typeID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the contents of the record back, so it can be written
|
|
|
|
* to disk
|
|
|
|
*/
|
|
|
|
public void writeOut(OutputStream out) throws IOException {
|
|
|
|
writeOut(_header[0],_header[1],getRecordType(),_children,out);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add font with the specified name to the font collection.
|
|
|
|
* If the font is already present return its index.
|
|
|
|
* @param name of the font
|
|
|
|
* @return zero based index of the font in the collection
|
|
|
|
*/
|
|
|
|
public int addFont(String name) {
|
|
|
|
for (int i = 0; i < fonts.size(); i++) {
|
|
|
|
if(fonts.get(i).equals(name)){
|
|
|
|
//if the font is already present return its index
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FontEntityAtom fnt = new FontEntityAtom();
|
|
|
|
fnt.setFontIndex(fonts.size() << 4);
|
|
|
|
fnt.setFontName(name);
|
|
|
|
fonts.add(name);
|
|
|
|
|
2006-03-19 12:53:49 -05:00
|
|
|
// Append new child to the end
|
|
|
|
appendChildRecord(fnt);
|
2005-08-02 13:16:20 -04:00
|
|
|
|
|
|
|
return fonts.size()-1; //the added font is the last in the list
|
|
|
|
}
|
2006-03-18 13:56:26 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the name of the font at the given ID, or null if there is
|
|
|
|
* no font at that ID.
|
|
|
|
* @param id
|
|
|
|
*/
|
|
|
|
public String getFontWithId(int id) {
|
|
|
|
if(id >= fonts.size()) {
|
|
|
|
// No font with that id
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (String)fonts.get(id);
|
|
|
|
}
|
2005-08-02 13:16:20 -04:00
|
|
|
}
|