summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvipng/color.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/dvipng/color.c')
-rw-r--r--Build/source/texk/dvipng/color.c164
1 files changed, 111 insertions, 53 deletions
diff --git a/Build/source/texk/dvipng/color.c b/Build/source/texk/dvipng/color.c
index a2cd5d6a502..a4cf484ae82 100644
--- a/Build/source/texk/dvipng/color.c
+++ b/Build/source/texk/dvipng/color.c
@@ -37,8 +37,11 @@ struct colorname {
struct colorname *next;
char* color;
char name[1];
-} *dvipsnam=NULL,*svgnam=NULL,*xcolor=NULL;
+} *colornamep=NULL,*xcp=NULL;
+char *colordef[]={"xcolor.sty","dvipsnam.def",
+ "svgnam.def","x11nam.def",NULL};
+char *xcpname=NULL;
void initcolor()
{
@@ -51,17 +54,19 @@ void initcolor()
cstack[1].blue=0;
}
-struct colorname * NewColor(char* name, int nname,
+struct colorname * NewColor(char* prefix, int nprefix,
+ char* name, int nname,
char* model, int nmodel,
char* values, int nvalues)
{
struct colorname *tmp =
- malloc(sizeof(struct colorname)+3+nname+nmodel+nvalues);
+ malloc(sizeof(struct colorname)+3+nprefix+nname+nmodel+nvalues);
if (tmp==NULL)
Fatal("Cannot allocate space for color name");
- tmp->color=tmp->name+nname+1;
- strncpy(tmp->name,name,nname);
- tmp->name[nname]='\0';
+ tmp->color=tmp->name+nprefix+nname+1;
+ strncpy(tmp->name,prefix,nprefix);
+ strncpy(tmp->name+nprefix,name,nname);
+ tmp->name[nprefix+nname]='\0';
strncpy(tmp->color,model,nmodel);
tmp->color[nmodel]=' ';
strncpy(tmp->color+nmodel+1,values,nvalues);
@@ -80,32 +85,40 @@ struct colorname * NewColor(char* name, int nname,
#define FINDWORD(s) while(s<max && \
(*s=='{'||*s==' '||*s=='%'||*s=='\n'||*s==';')) s++
#define FINDARG(s) while(s<max && *s!='{') s++; FINDWORD(s)
-#define FINDMODELEND(s,n) n=0; while(s<max && *s!='}') { s++; n++; }
+#define FINDMODELEND(s,n) n=0; while(s<max && *s!='}' && *s!='/') { s++; n++; }
#define FINDNAMEEND(s,n) n=0; while(s<max && *s!='}' && *s!=',') { s++; n++; }
-#define FINDVALEND(s,n) n=0; while(s<max && *s!='}' && *s!=';') { s++; n++; }
+#define FINDVALEND(s,n) n=0; while(s<max && *s!='}' && *s!='/' && *s!=';') { s++; n++; }
+#define FINDLASTVALEND(s) while(s<max && *s!='}' && *s!=';') s++
+#define FINDPSNAMEEND(s,n) n=0; while(s<max && *s!='{') { s++; n++; }
#define BLANKCOMMAS(s)
-struct colorname* LoadColornameFile(char* filename, bool should_exist)
+struct colorname* LoadColornameFile(char* filename)
{
struct colorname *list=NULL,*tmp=NULL;
char *filepath,*pos,*max;
- char *name,*values,*model;
- int nname,nvalues,nmodel;
+ char *prefix="",*name,*values,*model;
+ int nprefix=0,nname,nvalues,nmodel;
struct filemmap fmmap;
TEMPSTR(filepath,kpse_find_file(filename,kpse_tex_format,false));
- if (filepath == NULL) {
- if (should_exist)
- Warning("color name file '%s' could not be found",filename);
+ if (filepath == NULL)
return NULL;
- }
DEBUG_PRINT(DEBUG_COLOR,("\n OPEN COLOR NAMES:\t'%s'", filepath));
if (MmapFile(filepath,&fmmap)) return NULL;
pos=fmmap.data;
max=fmmap.data+fmmap.size;
while (pos<max && *pos!='\\') pos++;
while(pos+9<max && strncmp(pos,"\\endinput",9)!=0) {
- if (pos+17<max && strncmp(pos,"\\DefineNamedColor",17)==0) {
+ if ((pos+20<max && strncmp(pos,"\\def\\colornameprefix",20)==0)
+ || (pos+32<max
+ && strncmp(pos,"\\providecommand*\\colornameprefix",32)==0)) {
+ DEBUG_PRINT(DEBUG_COLOR,("\n \t'%.20s'", pos));
+ FINDARG(pos);
+ prefix=pos;
+ FINDNAMEEND(pos,nprefix);
+ DEBUG_PRINT(DEBUG_COLOR,("\n \tCOLOR PREFIX '%.*s'",nprefix,prefix));
+ } else if (pos+17<max && strncmp(pos,"\\DefineNamedColor",17)==0) {
+ DEBUG_PRINT(DEBUG_COLOR,("\n \t'%.17s'", pos));
model=NULL;
nname=nmodel=nvalues=0;
FINDARG(pos); /* skip first argument */
@@ -118,11 +131,13 @@ struct colorname* LoadColornameFile(char* filename, bool should_exist)
FINDARG(pos); /* find fourth argument: color values */
values=pos;
FINDVALEND(pos,nvalues);
- tmp=NewColor(name,nname,model,nmodel,values,nvalues);
+ tmp=NewColor(prefix,nprefix,name,nname,model,nmodel,values,nvalues);
tmp->next=list;
list=tmp;
- } else if (pos+15<max && strncmp(pos,"\\definecolorset",15)==0) {
+ } else if ((pos+15<max && strncmp(pos,"\\definecolorset",15)==0)
+ || (pos+16<max && strncmp(pos,"\\preparecolorset",16)==0)) {
char *model;
+ DEBUG_PRINT(DEBUG_COLOR,("\n \t'%.15s'", pos));
FINDARG(pos); /* find first argument: color model */
model=pos;
FINDMODELEND(pos,nmodel);
@@ -135,7 +150,8 @@ struct colorname* LoadColornameFile(char* filename, bool should_exist)
pos++;
values=pos;
FINDVALEND(pos,nvalues);
- tmp=NewColor(name,nname,model,nmodel,values,nvalues);
+ FINDLASTVALEND(pos);
+ tmp=NewColor(prefix,nprefix,name,nname,model,nmodel,values,nvalues);
tmp->next=list;
list=tmp;
FINDWORD(pos);
@@ -149,29 +165,73 @@ struct colorname* LoadColornameFile(char* filename, bool should_exist)
return(list);
}
-void ClearColorNames(void)
+void ClearXColorPrologue(void)
{
- struct colorname *tmp=dvipsnam,*next=NULL;
- while (tmp!=NULL) {
- next=tmp->next;
- free(tmp);
- tmp=next;
+ struct colorname *next;
+ while (xcp) {
+ next=xcp->next;
+ free(xcp);
+ xcp=next;
}
- dvipsnam=NULL;
- tmp=svgnam;
- while (tmp!=NULL) {
- next=tmp->next;
- free(tmp);
- tmp=next;
+ if (xcpname!=NULL) {
+ free(xcpname);
+ xcpname=NULL;
}
- svgnam=NULL;
- tmp=xcolor;
- while (tmp!=NULL) {
- next=tmp->next;
- free(tmp);
- tmp=next;
+}
+
+void ClearColorNames(void)
+{
+ struct colorname *next;
+ while (colornamep) {
+ next=colornamep->next;
+ free(colornamep);
+ colornamep=next;
+ }
+ ClearXColorPrologue();
+}
+
+void InitXColorPrologue(char* name)
+{
+ ClearXColorPrologue();
+ xcpname=malloc(strlen(name)+1);
+ if (xcpname==NULL)
+ Fatal("cannot malloc memory for xcolor prologue name");
+ strcpy(xcpname,name);
+}
+
+struct colorname* LoadXColorPrologue(void)
+{
+ struct colorname *list=NULL,*tmp=NULL;
+ char *filepath,*pos,*max;
+ char *prefix="",*name,*values,*model;
+ int nprefix=0,nname,nvalues,nmodel;
+ struct filemmap fmmap;
+
+ TEMPSTR(filepath,kpse_find_file(xcpname,kpse_program_text_format,false));
+ if (filepath == NULL)
+ return NULL;
+ DEBUG_PRINT(DEBUG_COLOR,("\n OPEN XCOLOR PROLOGUE:\t'%s'", filepath));
+ if (MmapFile(filepath,&fmmap)) return NULL;
+ pos=fmmap.data;
+ max=fmmap.data+fmmap.size;
+ while(pos<max) {
+ while (pos<max && *pos!='/') pos++;
+ if (*pos=='/') {
+ nname=nmodel=nvalues=0;
+ name=++pos; /* first argument: color name */
+ FINDPSNAMEEND(pos,nname);
+ values=++pos; /* second argument: color values */
+ FINDVALEND(pos,nvalues);
+ model=pos+3; /* third argument: color model, prefixed by 'XC' */
+ while(pos<max && *pos!=' ' && *pos!='\n') pos++;
+ nmodel=pos-model;
+ tmp=NewColor(prefix,nprefix,name,nname,model,nmodel,values,nvalues);
+ tmp->next=list;
+ list=tmp;
+ }
}
- xcolor=NULL;
+ UnMmapFile(&fmmap);
+ return(list);
}
#define FTO255(a) ((int) (255*a+0.5))
@@ -187,6 +247,7 @@ void ClearColorNames(void)
void stringrgb(char* color,int *r,int *g,int *b)
{
char* end;
+ static int unloaded=1;
DEBUG_PRINT(DEBUG_COLOR,("\n COLOR SPEC:\t'%s' (",color));
SKIPSPACES(color);
@@ -274,26 +335,23 @@ void stringrgb(char* color,int *r,int *g,int *b)
/* Model not found, probably a color name */
struct colorname *tmp;
- if (dvipsnam==NULL)
- dvipsnam=LoadColornameFile("dvipsnam.def",true);
- tmp=dvipsnam;
- while(tmp!=NULL && tmp->name!=NULL && strcmp(color,tmp->name))
+ if (xcp==NULL && xcpname!=NULL)
+ xcp=LoadXColorPrologue();
+ tmp=xcp;
+ while(tmp!=NULL && strcmp(color,tmp->name)!=0)
tmp=tmp->next;
if (tmp==NULL) {
- if (svgnam==NULL)
- svgnam=LoadColornameFile("svgnam.def",false);
- tmp=svgnam;
- while(tmp!=NULL && tmp->name!=NULL && strcmp(color,tmp->name))
+ if (colornamep==NULL)
+ colornamep=LoadColornameFile(colordef[0]);
+ tmp=colornamep;
+ while((tmp->next!=NULL || colordef[unloaded]!=NULL)
+ && strcmp(color,tmp->name)!=0) {
+ if (tmp->next==NULL)
+ tmp->next=LoadColornameFile(colordef[unloaded++]);
tmp=tmp->next;
- if (tmp==NULL) {
- if (xcolor==NULL)
- xcolor=LoadColornameFile("xcolor.sty",false);
- tmp=xcolor;
- while(tmp!=NULL && tmp->name!=NULL && strcmp(color,tmp->name))
- tmp=tmp->next;
}
}
- if (tmp!=NULL) {
+ if (strcmp(color,tmp->name)==0) {
/* Found: one-level recursion */
DEBUG_PRINT(DEBUG_COLOR,("\n ---RECURSION--- "))
stringrgb(tmp->color,r,g,b);