зеркало из https://github.com/mozilla/moz-skia.git
use real strtof and snprintf to parse and dump floats
git-svn-id: http://skia.googlecode.com/svn/trunk@369 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
bb9aea999c
Коммит
a8cf0aa533
|
@ -206,11 +206,20 @@ const char* SkParse::FindMSec(const char str[], SkMSec* value)
|
|||
return str;
|
||||
}
|
||||
|
||||
const char* SkParse::FindScalar(const char str[], SkScalar* value)
|
||||
{
|
||||
const char* SkParse::FindScalar(const char str[], SkScalar* value) {
|
||||
SkASSERT(str);
|
||||
str = skip_ws(str);
|
||||
|
||||
#ifdef SK_SCALAR_IS_FLOAT
|
||||
char* stop;
|
||||
float v = ::strtof(str, &stop);
|
||||
if (str == stop) {
|
||||
return NULL;
|
||||
}
|
||||
if (value) {
|
||||
*value = v;
|
||||
}
|
||||
return stop;
|
||||
#else
|
||||
int sign = 0;
|
||||
if (*str == '-')
|
||||
{
|
||||
|
@ -251,6 +260,7 @@ const char* SkParse::FindScalar(const char str[], SkScalar* value)
|
|||
n = (n ^ sign) - sign; // apply the sign
|
||||
*value = SkFixedToScalar(n);
|
||||
}
|
||||
#endif
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
|
@ -181,8 +181,14 @@ bool SkParsePath::FromSVGString(const char data[], SkPath* result) {
|
|||
#include "SkStream.h"
|
||||
|
||||
static void write_scalar(SkWStream* stream, SkScalar value) {
|
||||
#ifdef SK_SCALAR_IS_FLOAT
|
||||
char buffer[64];
|
||||
int len = snprintf(buffer, sizeof(buffer), "%g", value);
|
||||
char* stop = buffer + len;
|
||||
#else
|
||||
char buffer[SkStrAppendScalar_MaxSize];
|
||||
char* stop = SkStrAppendScalar(buffer, value);
|
||||
#endif
|
||||
stream->write(buffer, stop - buffer);
|
||||
}
|
||||
|
||||
|
@ -191,10 +197,7 @@ static void append_scalars(SkWStream* stream, char verb, const SkScalar data[],
|
|||
stream->write(&verb, 1);
|
||||
write_scalar(stream, data[0]);
|
||||
for (int i = 1; i < count; i++) {
|
||||
if (data[i] >= 0) {
|
||||
// can skip the separater if data[i] is negative
|
||||
stream->write(" ", 1);
|
||||
}
|
||||
write_scalar(stream, data[i]);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче