org.ttzero.excel.entity.style.FontParser Maven / Gradle / Ivy
/*
* Copyright (c) 2019-2020, [email protected] All Rights Reserved.
*
* Licensed 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
*
* 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.ttzero.excel.entity.style;
import org.ttzero.excel.entity.e3.Block;
import org.ttzero.excel.entity.e3.Option;
import org.ttzero.excel.entity.e3.ParserIdentifier;
import org.ttzero.excel.entity.e3.StringParser;
/**
* 5.45 FONT
*
* This record contains information about a used font,
* including character formatting. All FONT records
* occur together in a sequential list. Other records
* referencing a FONT record contain an index into this list.
*
* The font with index 4 is omitted in all BIFF versions.
* This means the first four fonts have zero-based indexes,
* and the fifth font and all following fonts are referenced
* with one-based indexes.
*
* @author guanquan.wang at 2019-02-28 19:27
*/
public class FontParser {
public static BIFFFont get(Block block) {
block.ready();
BIFFFont font = new BIFFFont();
// Height of the font (in twips = 1/20 of a point)
font.height = block.nextShort();
// Option flags, see below
font.optionFlag = Option.of(block.nextShort());
// Colour index (➜5.74)
font.colorIndex = block.nextShort();
// BIFFFont weight (100-1000). Standard values are 0190H (400) for normal text and 02BCH
// (700) for bold text
font.fontWeight = block.nextShort();
// Escapement type:
// 0000H = None
// 0001H = Superscript
// 0002H = Subscript
font.escapementType = block.nextShort();
// Underline type: 00H = None
// 01H = Single 21H = Single accounting
// 02H = Double 22H = Double accounting
font.underlineType = BIFFFont.UnderlineType.of(block.nextByte());
// BIFFFont family: 00H = None (unknown or don't care)
// 01H = Roman (variable width, serifed)
// 02H = Swiss (variable width, sans-serifed)
// 03H = Modern (fixed width, serifed or sans-serifed)
// 04H = Script (cursive)
// 05H = Decorative (specialised, for example Old English, Fraktur)
font.fontFamily = BIFFFont.FontFamily.of(block.nextByte());
// Character set (used by all cell records containing byte strings)
font.charset = (short) (block.nextByte() & 0xFF);
// Not used
block.skip(1);
// BIFFFont name: Unicode string, 8-bit string length (➜2.5.3)
font.fontName = StringParser.get8Bit(block);
block.commit();
return font;
}
public static short getId() {
return ParserIdentifier.FONT;
}
}