Commit 0b0f4c64 authored by aroben@apple.com's avatar aroben@apple.com
Browse files

Change WebKitGraphics truncation functions to return the length of the truncated string

        Reviewed by Darin Adler.

        * WebKitGraphics.cpp:
        (CenterTruncateStringToWidth):
        (RightTruncateStringToWidth):
        Return the length.
        * WebKitGraphics.h:
        The truncation functions now return an unsigned int that is the length
        of the truncated string. The whole file has been marked extern "C" to
        keep the symbols for these functions from changing (which would break
        nightly builds).

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@34834 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0e2a03ae
2008-06-27 Adam Roben <aroben@apple.com>
Change WebKitGraphics truncation functions to return the length of the
truncated string
Reviewed by Darin Adler.
* WebKitGraphics.cpp:
(CenterTruncateStringToWidth):
(RightTruncateStringToWidth):
Return the length.
* WebKitGraphics.h:
The truncation functions now return an unsigned int that is the length
of the truncated string. The whole file has been marked extern "C" to
keep the symbols for these functions from changing (which would break
nightly builds).
2008-06-19 Alexey Proskuryakov <ap@webkit.org>
 
Windows build fix.
......
......@@ -140,20 +140,22 @@ void FontMetrics(const WebFontDescription& description, int* ascent, int* descen
*lineSpacing = font.lineSpacing();
}
void CenterTruncateStringToWidth(LPCTSTR text, int length, const WebFontDescription& description, float width, WCHAR* buffer)
unsigned CenterTruncateStringToWidth(LPCTSTR text, int length, const WebFontDescription& description, float width, WCHAR* buffer)
{
ASSERT(buffer);
String result = StringTruncator::centerTruncate(String(text, length), width, makeFont(description), false);
memcpy(buffer, result.characters(), result.length() * sizeof(UChar));
buffer[result.length()] = '\0';
return result.length();
}
void RightTruncateStringToWidth(LPCTSTR text, int length, const WebFontDescription& description, float width, WCHAR* buffer)
unsigned RightTruncateStringToWidth(LPCTSTR text, int length, const WebFontDescription& description, float width, WCHAR* buffer)
{
ASSERT(buffer);
String result = StringTruncator::rightTruncate(String(text, length), width, makeFont(description), false);
memcpy(buffer, result.characters(), result.length() * sizeof(UChar));
buffer[result.length()] = '\0';
return result.length();
}
......@@ -28,6 +28,8 @@
#include <windows.h>
extern "C" {
typedef struct CGColor* CGColorRef;
typedef struct CGContext* CGContextRef;
......@@ -65,8 +67,10 @@ void WebDrawText(WebTextRenderInfo*);
float TextFloatWidth(LPCTSTR text, int length, const WebFontDescription&);
void FontMetrics(const WebFontDescription&, int* ascent, int* descent, int* lineSpacing);
// buffer must be large enough to hold all of "text", including its null terminator.
void CenterTruncateStringToWidth(LPCTSTR text, int length, const WebFontDescription&, float width, WCHAR* buffer);
void RightTruncateStringToWidth(LPCTSTR text, int length, const WebFontDescription&, float width, WCHAR* buffer);
// buffer must be large enough to hold all of "text", including its null terminator. Returns the number of characters put in buffer (excluding the null terminator).
unsigned CenterTruncateStringToWidth(LPCTSTR text, int length, const WebFontDescription&, float width, WCHAR* buffer);
unsigned RightTruncateStringToWidth(LPCTSTR text, int length, const WebFontDescription&, float width, WCHAR* buffer);
}
#endif // !defined(WebKitGraphics_h)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment