зеркало из https://github.com/mozilla/moz-skia.git
add GetFileName api to SkFontHost
git-svn-id: http://skia.googlecode.com/svn/trunk@299 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
61608aaf93
Коммит
ac98154faa
|
@ -87,7 +87,7 @@ public:
|
|||
the caller is responsible for calling unref() when it is no longer used.
|
||||
*/
|
||||
static SkTypeface* CreateTypefaceFromFile(const char path[]);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Returns true if the specified unique ID matches an existing font.
|
||||
|
@ -102,6 +102,35 @@ public:
|
|||
*/
|
||||
static SkStream* OpenStream(SkFontID uniqueID);
|
||||
|
||||
/** Some fonts are stored in files. If that is true for the fontID, then
|
||||
this returns the byte length of the full file path. If path is not null,
|
||||
then the full path is copied into path (allocated by the caller), up to
|
||||
length bytes. If index is not null, then it is set to the truetype
|
||||
collection index for this font, or 0 if the font is not in a collection.
|
||||
|
||||
Note: GetFileName does not assume that path is a null-terminated string,
|
||||
so when it succeeds, it only copies the bytes of the file name and
|
||||
nothing else (i.e. it copies exactly the number of bytes returned by the
|
||||
function. If the caller wants to treat path[] as a C string, it must be
|
||||
sure that it is allocated at least 1 byte larger than the returned size,
|
||||
and it must copy in the terminating 0.
|
||||
|
||||
If the fontID does not correspond to a file, then the function returns
|
||||
0, and the path and index parameters are ignored.
|
||||
|
||||
@param fontID The font whose file name is being queried
|
||||
@param path Either NULL, or storage for receiving up to length bytes
|
||||
of the font's file name. Allocated by the caller.
|
||||
@param length The maximum space allocated in path (by the caller).
|
||||
Ignored if path is NULL.
|
||||
@param index Either NULL, or receives the TTC index for this font.
|
||||
If the font is not a TTC, then will be set to 0.
|
||||
@return The byte length of th font's file name, or 0 if the font is not
|
||||
baked by a file.
|
||||
*/
|
||||
static size_t GetFileName(SkFontID fontID, char path[], size_t length,
|
||||
int32_t* index);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Write a unique identifier to the stream, so that the same typeface can
|
||||
|
|
|
@ -287,6 +287,12 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
|
||||
int32_t* index) {
|
||||
SkDebugf("SkFontHost::GetFileName unimplemented\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SkFontHost::Serialize(const SkTypeface* tface, SkWStream* stream) {
|
||||
const FontFaceRec* face = &((const FontFaceRec_Typeface*)tface)->fFace;
|
||||
stream->write(face, sizeof(face));
|
||||
|
|
|
@ -267,6 +267,7 @@ public:
|
|||
|
||||
virtual SkStream* openStream() = 0;
|
||||
virtual const char* getUniqueString() const = 0;
|
||||
virtual const char* getFilePath() const = 0;
|
||||
|
||||
private:
|
||||
bool fIsSysFont;
|
||||
|
@ -297,6 +298,7 @@ public:
|
|||
return fStream;
|
||||
}
|
||||
virtual const char* getUniqueString() const { return NULL; }
|
||||
virtual const char* getFilePath() const { return NULL; }
|
||||
|
||||
private:
|
||||
SkStream* fStream;
|
||||
|
@ -341,6 +343,9 @@ public:
|
|||
}
|
||||
return str;
|
||||
}
|
||||
virtual const char* getFilePath() const {
|
||||
return fPath.c_str();
|
||||
}
|
||||
|
||||
private:
|
||||
SkString fPath;
|
||||
|
@ -592,6 +597,27 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID) {
|
|||
return stream;
|
||||
}
|
||||
|
||||
size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
|
||||
int32_t* index) {
|
||||
SkAutoMutexAcquire ac(gFamilyMutex);
|
||||
|
||||
FamilyTypeface* tf = (FamilyTypeface*)find_from_uniqueID(fontID);
|
||||
const char* src = tf ? tf->getFilePath() : NULL;
|
||||
|
||||
if (src) {
|
||||
size_t size = strlen(src);
|
||||
if (path) {
|
||||
memcpy(path, src, SkMin32(size, length));
|
||||
}
|
||||
if (index) {
|
||||
*index = 0; // we don't have collections (yet)
|
||||
}
|
||||
return size;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t SkFontHost::NextLogicalFont(uint32_t fontID) {
|
||||
load_system_fonts();
|
||||
|
||||
|
|
|
@ -333,6 +333,27 @@ SkStream* SkFontHost::OpenStream(uint32_t id)
|
|||
return SkNEW_ARGS(SkFILEStream, (i->second.c_str()));
|
||||
}
|
||||
|
||||
size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
|
||||
int32_t* index) {
|
||||
SkAutoMutexAcquire ac(global_fc_map_lock);
|
||||
const unsigned fileid = UniqueIdToFileId(id);
|
||||
|
||||
std::map<unsigned, std::string>::const_iterator i =
|
||||
global_fc_map_inverted.find(fileid);
|
||||
if (i == global_fc_map_inverted.end()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const std::string& str = i->second;
|
||||
if (path) {
|
||||
memcpy(path, str.c_str(), SkMin32(str.size(), length));
|
||||
}
|
||||
if (index) { // TODO: check if we're in a TTC
|
||||
*index = 0;
|
||||
}
|
||||
return str.size();
|
||||
}
|
||||
|
||||
void SkFontHost::Serialize(const SkTypeface*, SkWStream*) {
|
||||
SkASSERT(!"SkFontHost::Serialize unimplemented");
|
||||
}
|
||||
|
|
|
@ -539,6 +539,12 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID) {
|
|||
return stream;
|
||||
}
|
||||
|
||||
size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
|
||||
int32_t* index) {
|
||||
SkDebugf("SkFontHost::GetFileName unimplemented\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SkFontHost::CloseStream(uint32_t fontID, SkStream* stream) {
|
||||
FamilyTypeface* tf = (FamilyTypeface*)SkFontHost::ResolveTypeface(fontID);
|
||||
if (NULL != tf) {
|
||||
|
|
|
@ -44,6 +44,12 @@ SkStream* SkFontHost::OpenStream(uint32_t uniqueID) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length,
|
||||
int32_t* index) {
|
||||
SkDebugf("SkFontHost::GetFileName unimplemented\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче