00001 /* 00002 * Copyright (C) 2006 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SkTypeface_DEFINED 00018 #define SkTypeface_DEFINED 00019 00020 #include "SkRefCnt.h" 00021 00022 class SkStream; 00023 class SkWStream; 00024 00034 class SkTypeface : public SkRefCnt { 00035 public: 00038 enum Style { 00039 kNormal = 0, 00040 kBold = 0x01, 00041 kItalic = 0x02, 00042 00043 // helpers 00044 kBoldItalic = 0x03 00045 }; 00046 00049 Style style() const { return fStyle; } 00050 00053 bool isBold() const { return (fStyle & kBold) != 0; } 00054 00057 bool isItalic() const { return (fStyle & kItalic) != 0; } 00058 00062 uint32_t uniqueID() const { return fUniqueID; } 00063 00068 static uint32_t UniqueID(const SkTypeface* face); 00069 00073 static bool Equal(const SkTypeface* facea, const SkTypeface* faceb); 00074 00084 static SkTypeface* CreateFromName(const char familyName[], Style style); 00085 00096 static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style s); 00097 00101 static SkTypeface* CreateFromFile(const char path[]); 00102 00107 static SkTypeface* CreateFromStream(SkStream* stream); 00108 00112 void serialize(SkWStream*) const; 00113 00119 static SkTypeface* Deserialize(SkStream*); 00120 00121 protected: 00124 SkTypeface(Style style, uint32_t uniqueID) 00125 : fUniqueID(uniqueID), fStyle(style) {} 00126 00127 private: 00128 uint32_t fUniqueID; 00129 Style fStyle; 00130 00131 typedef SkRefCnt INHERITED; 00132 }; 00133 00134 #endif