зеркало из https://github.com/mozilla/gecko-dev.git
update to new color apis
This commit is contained in:
Родитель
e2cf60152f
Коммит
223b3d7794
|
@ -19,13 +19,15 @@
|
|||
#include <stdio.h>
|
||||
#include "nsColor.h"
|
||||
#include "nsColorNames.h"
|
||||
#include "nsString.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const nsColorNames::NameTableEntry* et = &nsColorNames::kNameTable[0];
|
||||
for (int i = 0; i < COLOR_MAX; i++, et++) {
|
||||
char buffer[1024];
|
||||
for (int i = 0; i < eColorName_COUNT; i++) {
|
||||
nscolor rgba = nsColorNames::kColors[i];
|
||||
printf("%s: NS_RGB(%d,%d,%d,%d)\n", et->name,
|
||||
nsColorNames::GetStringValue(nsColorName(i)).ToCString(buffer, sizeof(buffer));
|
||||
printf("%s: NS_RGB(%d,%d,%d,%d)\n", buffer,
|
||||
NS_GET_R(rgba), NS_GET_G(rgba), NS_GET_B(rgba), NS_GET_A(rgba));
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <string.h>
|
||||
#include "nsColorNames.h"
|
||||
#include "prprf.h"
|
||||
#include "nsString.h"
|
||||
|
||||
static const char* kJunkNames[] = {
|
||||
nsnull,
|
||||
|
@ -34,50 +35,53 @@ static const char* kJunkNames[] = {
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
PRInt32 id;
|
||||
nsColorName id;
|
||||
nsColorName index;
|
||||
int rv = 0;
|
||||
|
||||
// First make sure we can find all of the tags that are supposed to
|
||||
// be in the table. Futz with the case to make sure any case will
|
||||
// work
|
||||
const nsColorNames::NameTableEntry* et = &nsColorNames::kNameTable[0];
|
||||
const nsColorNames::NameTableEntry* end = &nsColorNames::kNameTable[COLOR_MAX];
|
||||
while (et < end) {
|
||||
|
||||
index = eColorName_UNKNOWN;
|
||||
while (PRInt32(index) < (PRInt32 (eColorName_COUNT) - 1)) {
|
||||
// Lookup color by name and make sure it has the right id
|
||||
char tagName[100];
|
||||
id = nsColorNames::LookupName(et->name);
|
||||
if (id < 0) {
|
||||
printf("bug: can't find '%s'\n", et->name);
|
||||
char tagName[512];
|
||||
index = nsColorName(PRInt32(index) + 1);
|
||||
nsColorNames::GetStringValue(index).ToCString(tagName, sizeof(tagName));
|
||||
|
||||
id = nsColorNames::LookupName(nsAutoString(tagName));
|
||||
if (id == eColorName_UNKNOWN) {
|
||||
printf("bug: can't find '%s'\n", tagName);
|
||||
rv = -1;
|
||||
}
|
||||
if (et->id != id) {
|
||||
printf("bug: name='%s' et->id=%d id=%d\n", et->name, et->id, id);
|
||||
if (id != index) {
|
||||
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
// fiddle with the case to make sure we can still find it
|
||||
strcpy(tagName, et->name);
|
||||
tagName[0] = tagName[0] - 32;
|
||||
id = nsColorNames::LookupName(tagName);
|
||||
if (id < 0) {
|
||||
id = nsColorNames::LookupName(nsAutoString(tagName));
|
||||
if (id == eColorName_UNKNOWN) {
|
||||
printf("bug: can't find '%s'\n", tagName);
|
||||
rv = -1;
|
||||
}
|
||||
if (et->id != id) {
|
||||
printf("bug: name='%s' et->id=%d id=%d\n", et->name, et->id, id);
|
||||
if (id != index) {
|
||||
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
// Check that color lookup by name gets the right rgb value
|
||||
nscolor rgb;
|
||||
if (!NS_ColorNameToRGB(et->name, &rgb)) {
|
||||
printf("bug: name='%s' didn't NS_ColorNameToRGB\n", et->name);
|
||||
if (!NS_ColorNameToRGB(nsAutoString(tagName), &rgb)) {
|
||||
printf("bug: name='%s' didn't NS_ColorNameToRGB\n", tagName);
|
||||
rv = -1;
|
||||
}
|
||||
if (nsColorNames::kColors[et->id] != rgb) {
|
||||
if (nsColorNames::kColors[index] != rgb) {
|
||||
printf("bug: name='%s' ColorNameToRGB=%x kColors[%d]=%x\n",
|
||||
et->name, rgb, nsColorNames::kColors[et->id],
|
||||
nsColorNames::kColors[et->id]);
|
||||
tagName, rgb, nsColorNames::kColors[index],
|
||||
nsColorNames::kColors[index]);
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
|
@ -86,13 +90,9 @@ int main(int argc, char** argv)
|
|||
PRUint8 g = NS_GET_G(rgb);
|
||||
PRUint8 b = NS_GET_B(rgb);
|
||||
char cbuf[50];
|
||||
PR_snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x", r, g, b);
|
||||
PR_snprintf(cbuf, sizeof(cbuf), "%02x%02x%02x", r, g, b);
|
||||
nscolor hexrgb;
|
||||
if (!NS_HexToRGB(cbuf, &hexrgb)) {
|
||||
printf("bug: hex conversion to color of '%s' failed\n", cbuf);
|
||||
rv = -1;
|
||||
}
|
||||
if (!NS_HexToRGB(cbuf + 1, &hexrgb)) {
|
||||
if (!NS_HexToRGB(nsAutoString(cbuf), &hexrgb)) {
|
||||
printf("bug: hex conversion to color of '%s' failed\n", cbuf);
|
||||
rv = -1;
|
||||
}
|
||||
|
@ -100,14 +100,13 @@ int main(int argc, char** argv)
|
|||
printf("bug: rgb=%x hexrgb=%x\n", rgb, hexrgb);
|
||||
rv = -1;
|
||||
}
|
||||
et++;
|
||||
}
|
||||
|
||||
// Now make sure we don't find some garbage
|
||||
for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) {
|
||||
const char* tag = kJunkNames[i];
|
||||
id = nsColorNames::LookupName(tag);
|
||||
if (id >= 0) {
|
||||
id = nsColorNames::LookupName(nsAutoString(tag));
|
||||
if (id > eColorName_UNKNOWN) {
|
||||
printf("bug: found '%s'\n", tag ? tag : "(null)");
|
||||
rv = -1;
|
||||
}
|
||||
|
|
|
@ -647,8 +647,8 @@ nscolor white,black;
|
|||
aSurface->SetFont(*font);
|
||||
|
||||
// clear surface
|
||||
NS_ColorNameToRGB("white", &white);
|
||||
NS_ColorNameToRGB("red", &black);
|
||||
NS_ColorNameToRGB(nsAutoString("white"), &white);
|
||||
NS_ColorNameToRGB(nsAutoString("red"), &black);
|
||||
aSurface->SetColor(white);
|
||||
aSurface->FillRect(0,0,1000,1000);
|
||||
aSurface->SetColor(black);
|
||||
|
@ -687,8 +687,8 @@ nscolor white,black;
|
|||
|
||||
|
||||
// clear surface
|
||||
NS_ColorNameToRGB("white", &white);
|
||||
NS_ColorNameToRGB("black", &black);
|
||||
NS_ColorNameToRGB(nsAutoString("white"), &white);
|
||||
NS_ColorNameToRGB(nsAutoString("black"), &black);
|
||||
aSurface->SetColor(white);
|
||||
aSurface->FillRect(0,0,1000,1000);
|
||||
aSurface->SetColor(black);
|
||||
|
@ -741,8 +741,8 @@ nscolor white,black;
|
|||
aSurface->SetFont(*font);
|
||||
|
||||
// clear surface
|
||||
NS_ColorNameToRGB("white", &white);
|
||||
NS_ColorNameToRGB("black", &black);
|
||||
NS_ColorNameToRGB(nsAutoString("white"), &white);
|
||||
NS_ColorNameToRGB(nsAutoString("black"), &black);
|
||||
aSurface->SetColor(white);
|
||||
aSurface->FillRect(0,0,1000,1000);
|
||||
aSurface->SetColor(black);
|
||||
|
@ -875,13 +875,13 @@ char *str;
|
|||
if(aGenLoad == PR_TRUE)
|
||||
{
|
||||
MyBlendObserver *observer = new MyBlendObserver(aTheImage);
|
||||
NS_ColorNameToRGB("white", &white);
|
||||
NS_ColorNameToRGB(nsAutoString("white"), &white);
|
||||
gImageReq = gImageGroup->GetImage(fileURL,observer,&white, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
MyObserver *observer = new MyObserver();
|
||||
NS_ColorNameToRGB("white", &white);
|
||||
NS_ColorNameToRGB(nsAutoString("white"), &white);
|
||||
gImageReq = gImageGroup->GetImage(fileURL,observer,&white, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче