More work on the BFont special functions.

* Reworked functions like GetEscapements(), GetBoundingBoxesAsString() and GetGlyphShapes() completely
* Made the ServerFont functions uniform in their prototypes and cleaned out unnecessary arguments
* Added new UTF8 handling functions to moreUTF8.h that are now used by ServerFont
* Put the common transformations of the FT_Face into an own GetTransformedFace() to lessen code duplication

In other words, ServerFont is now cleaned and handles UTF8 pretty efficiently. Some ToDo's are still left though.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16241 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2006-02-05 23:36:59 +00:00
parent 2bdbc03a1d
commit db5734a452
5 changed files with 384 additions and 347 deletions
+108
View File
@@ -98,4 +98,112 @@ UTF8CountChars(const char *text, int32 numBytes)
}
/* UTF8ToCharCode converts the input that includes potential multibyte chars
to UTF-32 char codes that can be used by FreeType. The string pointer is
then advanced to the next character in the string. In case the terminating
0 is reached, the string pointer is not advanced anymore and spaces are
returned. This makes it safe to overruns and enables streamed processing
of UTF8 strings. */
static inline uint32
UTF8ToCharCode(const char **bytes)
{
register uint32 result = 0;
if ((*bytes)[0] & 0x80) {
if ((*bytes)[0] & 0x40) {
if ((*bytes)[0] & 0x20) {
if ((*bytes)[0] & 0x10) {
if ((*bytes)[0] & 0x08) {
/* A five byte char?!
Something's wrong, substitue. */
result += 0x20;
(*bytes)++;
return result;
}
/* A four byte char */
result += (*bytes)[0] & 0x07;
result <<= 6;
result += (*bytes)[1] & 0x3f;
result <<= 6;
result += (*bytes)[2] & 0x3f;
result <<= 6;
result += (*bytes)[3] & 0x3f;
(*bytes) += 3;
return result;
}
/* A three byte char */
result += (*bytes)[0] & 0x0f;
result <<= 6;
result += (*bytes)[1] & 0x3f;
result <<= 6;
result += (*bytes)[2] & 0x3f;
(*bytes) += 3;
return result;
}
/* A two byte char */
result += (*bytes)[0] & 0x1f;
result <<= 6;
result += (*bytes)[1] & 0x3f;
(*bytes) += 2;
return result;
}
/* This (10) is not a startbyte.
Substitute with a space. */
result += 0x20;
(*bytes)++;
return result;
}
if ((*bytes)[0] == 0) {
/* We do not advance beyond the terminating 0. Just pad any further
request with spaces. */
result += 0x20;
return result;
}
result += (*bytes)[0];
(*bytes)++;
return result;
}
/* UTF8ToLength works like strlen() but takes UTF8 encoded multibyte chars
into account. It's a quicker version of UTF8CountChars above. */
static inline int32
UTF8ToLength(const char *bytes)
{
int32 length = 0;
while (*bytes) {
length++;
if (bytes[0] & 0x80) {
if (bytes[0] & 0x40) {
if (bytes[0] & 0x20) {
if (bytes[0] & 0x10) {
bytes += 4;
continue;
}
bytes += 3;
continue;
}
bytes += 2;
continue;
}
/* Not a startbyte - skip */
}
bytes += 1;
}
return length;
}
#endif
+25 -19
View File
@@ -107,33 +107,39 @@ class ServerFont {
uint16 CharMapCount() const
{ return fStyle->CharMapCount(); }
BShape** GetGlyphShapes(const char charArray[],
int32 numChars) const;
void GetHasGlyphs(const char charArray[],
FT_Face GetTransformedFace(bool rotate, bool shear) const;
void PutTransformedFace(FT_Face face) const;
status_t GetGlyphShapes(const char charArray[],
int32 numChars, BShape *shapeArray[]) const;
status_t GetHasGlyphs(const char charArray[],
int32 numChars, bool hasArray[]) const;
void GetEdges(const char charArray[],
status_t GetEdges(const char charArray[],
int32 numChars, edge_info edgeArray[]) const;
BPoint* GetEscapements(const char charArray[],
int32 numChars,
BPoint offsetArray[]) const;
bool GetEscapements(const char charArray[],
int32 numChars,
int32 numBytes,
float widthArray[],
escapement_delta delta) const;
status_t GetEscapements(const char charArray[],
int32 numChars, escapement_delta delta,
BPoint escapementArray[],
BPoint offsetArray[]) const;
bool GetBoundingBoxesAsString(const char charArray[],
int32 numChars, BRect rectArray[], bool string_escapement,
font_metric_mode mode, escapement_delta delta);
status_t GetEscapements(const char charArray[],
int32 numChars, escapement_delta delta,
float widthArray[]) const;
bool GetBoundingBoxesForStrings(char *charArray[], int32 lengthArray[],
int32 numStrings, BRect rectArray[],
font_metric_mode mode, escapement_delta deltaArray[]);
status_t GetBoundingBoxesAsString(const char charArray[],
int32 numChars, BRect rectArray[],
bool stringEscapement, font_metric_mode mode,
escapement_delta delta);
float StringWidth(const char* string, int32 numBytes) const;
status_t GetBoundingBoxesForStrings(char *charArray[],
int32 lengthArray[], int32 numStrings,
BRect rectArray[], font_metric_mode mode,
escapement_delta deltaArray[]);
float StringWidth(const char *string, int32 numChars) const;
bool Lock() const { return fStyle->Lock(); }
void Unlock() const { fStyle->Unlock(); }