fontconfig/src/fcdbg.c

464 lines
12 KiB
C
Raw Normal View History

2002-02-15 00:34:13 +01:00
/*
2008-08-12 22:34:24 +02:00
* fontconfig/src/fcdbg.c
2002-02-15 00:34:13 +01:00
*
2004-12-07 02:14:46 +01:00
* Copyright © 2000 Keith Packard
2002-02-15 00:34:13 +01:00
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of the author(s) not be used in
2002-02-15 00:34:13 +01:00
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. The authors make no
2002-02-15 00:34:13 +01:00
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
2002-02-15 00:34:13 +01:00
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
2002-02-15 00:34:13 +01:00
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include "fcint.h"
2002-02-15 00:34:13 +01:00
#include <stdio.h>
#include <stdlib.h>
static void
_FcValuePrint (const FcValue v)
2002-02-15 00:34:13 +01:00
{
switch (v.type) {
case FcTypeVoid:
printf ("<void>");
2002-02-15 00:34:13 +01:00
break;
case FcTypeInteger:
printf ("%d(i)", v.u.i);
2002-02-15 00:34:13 +01:00
break;
case FcTypeDouble:
printf ("%g(f)", v.u.d);
2002-02-15 00:34:13 +01:00
break;
case FcTypeString:
printf ("\"%s\"", v.u.s);
2002-02-15 00:34:13 +01:00
break;
case FcTypeBool:
printf ("%s", v.u.b ? "True" : "False");
2002-02-15 00:34:13 +01:00
break;
case FcTypeMatrix:
printf ("[%g %g; %g %g]", v.u.m->xx, v.u.m->xy, v.u.m->yx, v.u.m->yy);
2002-02-15 00:34:13 +01:00
break;
case FcTypeCharSet: /* XXX */
FcCharSetPrint (v.u.c);
break;
case FcTypeLangSet:
FcLangSetPrint (v.u.l);
2002-02-15 00:34:13 +01:00
break;
case FcTypeFTFace:
printf ("face");
break;
}
}
void
FcValuePrint (const FcValue v)
{
printf (" ");
_FcValuePrint (v);
}
void
FcValuePrintWithPosition (const FcValue v, FcBool show_pos_mark)
{
if (show_pos_mark)
printf (" [insert here] ");
else
printf (" ");
_FcValuePrint (v);
}
static void
FcValueBindingPrint (const FcValueListPtr l)
{
switch (l->binding) {
case FcValueBindingWeak:
printf ("(w)");
break;
case FcValueBindingStrong:
printf ("(s)");
break;
case FcValueBindingSame:
printf ("(=)");
break;
2002-02-15 00:34:13 +01:00
}
}
void
FcValueListPrintWithPosition (FcValueListPtr l, const FcValueListPtr pos)
{
for (; l != NULL; l = FcValueListNext(l))
{
FcValuePrintWithPosition (FcValueCanonicalize (&l->value), pos != NULL && l == pos);
FcValueBindingPrint (l);
}
if (!pos)
printf (" [insert here]");
}
2002-02-15 00:34:13 +01:00
void
Add functionality to allow fontconfig data structure serialization. This patch allows the fundamental fontconfig data structures to be serialized. I've converted everything from FcPattern down to be able to use *Ptr objects, which can be either static or dynamic (using a union which either contains a pointer or an index) and replaced storage of pointers in the heap with the appropriate *Ptr object. I then changed all writes of pointers to the heap with a *CreateDynamic call, which creates a dynamic Ptr object pointing to the same object as before. This way, the fundamental fontconfig semantics should be unchanged; I did not have to change external signatures this way, although I did change some internal signatures. When given a *Ptr object, just run *U to get back to a normal pointer; it gives the right answer regardless of whether we're using static or dynamic storage. I've also implemented a Fc*Serialize call. Calling FcFontSetSerialize converts the dynamic FcFontSets contained in the config object to static FcFontSets and also converts its dependencies (e.g. everything you'd need to write to disk) to static objects. Note that you have to call Fc*PrepareSerialize first; this call will count the number of objects that actually needs to be allocated, so that we can avoid realloc. The Fc*Serialize calls then check the static pointers for nullness, and allocate the buffers if necessary. I've tested the execution of fc-list and fc-match after Fc*Serialize and they appear to work the same way.
2005-06-28 05:41:02 +02:00
FcValueListPrint (FcValueListPtr l)
2002-02-15 00:34:13 +01:00
{
for (; l != NULL; l = FcValueListNext(l))
{
FcValuePrint (FcValueCanonicalize (&l->value));
FcValueBindingPrint (l);
}
2002-02-15 00:34:13 +01:00
}
void
2003-03-05 06:52:51 +01:00
FcLangSetPrint (const FcLangSet *ls)
{
FcStrBuf buf;
FcChar8 init_buf[1024];
2010-04-12 18:18:50 +02:00
2003-03-05 06:52:51 +01:00
FcStrBufInit (&buf, init_buf, sizeof (init_buf));
if (FcNameUnparseLangSet (&buf, ls) && FcStrBufChar (&buf,'\0'))
Add functionality to allow fontconfig data structure serialization. This patch allows the fundamental fontconfig data structures to be serialized. I've converted everything from FcPattern down to be able to use *Ptr objects, which can be either static or dynamic (using a union which either contains a pointer or an index) and replaced storage of pointers in the heap with the appropriate *Ptr object. I then changed all writes of pointers to the heap with a *CreateDynamic call, which creates a dynamic Ptr object pointing to the same object as before. This way, the fundamental fontconfig semantics should be unchanged; I did not have to change external signatures this way, although I did change some internal signatures. When given a *Ptr object, just run *U to get back to a normal pointer; it gives the right answer regardless of whether we're using static or dynamic storage. I've also implemented a Fc*Serialize call. Calling FcFontSetSerialize converts the dynamic FcFontSets contained in the config object to static FcFontSets and also converts its dependencies (e.g. everything you'd need to write to disk) to static objects. Note that you have to call Fc*PrepareSerialize first; this call will count the number of objects that actually needs to be allocated, so that we can avoid realloc. The Fc*Serialize calls then check the static pointers for nullness, and allocate the buffers if necessary. I've tested the execution of fc-list and fc-match after Fc*Serialize and they appear to work the same way.
2005-06-28 05:41:02 +02:00
printf ("%s", buf.buf);
2003-03-05 06:52:51 +01:00
else
Add functionality to allow fontconfig data structure serialization. This patch allows the fundamental fontconfig data structures to be serialized. I've converted everything from FcPattern down to be able to use *Ptr objects, which can be either static or dynamic (using a union which either contains a pointer or an index) and replaced storage of pointers in the heap with the appropriate *Ptr object. I then changed all writes of pointers to the heap with a *CreateDynamic call, which creates a dynamic Ptr object pointing to the same object as before. This way, the fundamental fontconfig semantics should be unchanged; I did not have to change external signatures this way, although I did change some internal signatures. When given a *Ptr object, just run *U to get back to a normal pointer; it gives the right answer regardless of whether we're using static or dynamic storage. I've also implemented a Fc*Serialize call. Calling FcFontSetSerialize converts the dynamic FcFontSets contained in the config object to static FcFontSets and also converts its dependencies (e.g. everything you'd need to write to disk) to static objects. Note that you have to call Fc*PrepareSerialize first; this call will count the number of objects that actually needs to be allocated, so that we can avoid realloc. The Fc*Serialize calls then check the static pointers for nullness, and allocate the buffers if necessary. I've tested the execution of fc-list and fc-match after Fc*Serialize and they appear to work the same way.
2005-06-28 05:41:02 +02:00
printf ("langset (alloc error)");
2003-03-05 06:52:51 +01:00
FcStrBufDestroy (&buf);
}
void
FcCharSetPrint (const FcCharSet *c)
{
int i, j;
intptr_t *leaves = FcCharSetLeaves (c);
FcChar16 *numbers = FcCharSetNumbers (c);
2010-04-12 18:18:50 +02:00
#if 0
printf ("CharSet 0x%x\n", (intptr_t) c);
printf ("Leaves: +%d = 0x%x\n", c->leaves_offset, (intptr_t) leaves);
printf ("Numbers: +%d = 0x%x\n", c->numbers_offset, (intptr_t) numbers);
2010-04-12 18:18:50 +02:00
for (i = 0; i < c->num; i++)
{
2010-04-12 18:18:50 +02:00
printf ("Page %d: %04x +%d = 0x%x\n",
i, numbers[i], leaves[i],
(intptr_t) FcOffsetToPtr (leaves, leaves[i], FcCharLeaf));
}
#endif
2009-07-28 20:23:10 +02:00
printf ("\n");
for (i = 0; i < c->num; i++)
{
intptr_t leaf_offset = leaves[i];
FcCharLeaf *leaf = FcOffsetToPtr (leaves, leaf_offset, FcCharLeaf);
2009-07-28 20:23:10 +02:00
printf ("\t");
printf ("%04x:", numbers[i]);
for (j = 0; j < 256/32; j++)
printf (" %08x", leaf->map[j]);
printf ("\n");
}
}
2003-03-05 06:52:51 +01:00
void
FcPatternPrint (const FcPattern *p)
2002-02-15 00:34:13 +01:00
{
int i;
FcPatternElt *e;
2010-04-12 18:18:50 +02:00
2002-02-15 00:34:13 +01:00
if (!p)
{
printf ("Null pattern\n");
return;
}
printf ("Pattern has %d elts (size %d)\n", p->num, p->size);
2002-02-15 00:34:13 +01:00
for (i = 0; i < p->num; i++)
{
e = &FcPatternElts(p)[i];
printf ("\t%s:", FcObjectName(e->object));
FcValueListPrint (FcPatternEltValues(e));
2002-02-15 00:34:13 +01:00
printf ("\n");
}
printf ("\n");
}
#define FcOpFlagsPrint(_o_) \
{ \
int f = FC_OP_GET_FLAGS (_o_); \
if (f & FcOpFlagIgnoreBlanks) \
printf ("(ignore blanks)"); \
}
2002-02-15 00:34:13 +01:00
void
FcOpPrint (FcOp op_)
2002-02-15 00:34:13 +01:00
{
FcOp op = FC_OP_GET_OP (op_);
2002-02-15 00:34:13 +01:00
switch (op) {
case FcOpInteger: printf ("Integer"); break;
case FcOpDouble: printf ("Double"); break;
case FcOpString: printf ("String"); break;
case FcOpMatrix: printf ("Matrix"); break;
case FcOpRange: printf ("Range"); break;
2002-02-15 00:34:13 +01:00
case FcOpBool: printf ("Bool"); break;
case FcOpCharSet: printf ("CharSet"); break;
case FcOpLangSet: printf ("LangSet"); break;
2002-02-15 00:34:13 +01:00
case FcOpField: printf ("Field"); break;
case FcOpConst: printf ("Const"); break;
case FcOpAssign: printf ("Assign"); break;
case FcOpAssignReplace: printf ("AssignReplace"); break;
case FcOpPrepend: printf ("Prepend"); break;
case FcOpPrependFirst: printf ("PrependFirst"); break;
case FcOpAppend: printf ("Append"); break;
case FcOpAppendLast: printf ("AppendLast"); break;
case FcOpQuest: printf ("Quest"); break;
case FcOpOr: printf ("Or"); break;
case FcOpAnd: printf ("And"); break;
case FcOpEqual: printf ("Equal"); FcOpFlagsPrint (op_); break;
case FcOpNotEqual: printf ("NotEqual"); FcOpFlagsPrint (op_); break;
2002-02-15 00:34:13 +01:00
case FcOpLess: printf ("Less"); break;
case FcOpLessEqual: printf ("LessEqual"); break;
case FcOpMore: printf ("More"); break;
case FcOpMoreEqual: printf ("MoreEqual"); break;
case FcOpContains: printf ("Contains"); break;
case FcOpNotContains: printf ("NotContains"); break;
2002-02-15 00:34:13 +01:00
case FcOpPlus: printf ("Plus"); break;
case FcOpMinus: printf ("Minus"); break;
case FcOpTimes: printf ("Times"); break;
case FcOpDivide: printf ("Divide"); break;
case FcOpNot: printf ("Not"); break;
case FcOpNil: printf ("Nil"); break;
case FcOpComma: printf ("Comma"); break;
case FcOpFloor: printf ("Floor"); break;
case FcOpCeil: printf ("Ceil"); break;
case FcOpRound: printf ("Round"); break;
case FcOpTrunc: printf ("Trunc"); break;
case FcOpListing: printf ("Listing"); FcOpFlagsPrint (op_); break;
2002-02-15 00:34:13 +01:00
case FcOpInvalid: printf ("Invalid"); break;
}
}
void
FcExprPrint (const FcExpr *expr)
2002-02-15 00:34:13 +01:00
{
if (!expr) printf ("none");
else switch (FC_OP_GET_OP (expr->op)) {
2002-02-15 00:34:13 +01:00
case FcOpInteger: printf ("%d", expr->u.ival); break;
case FcOpDouble: printf ("%g", expr->u.dval); break;
case FcOpString: printf ("\"%s\"", expr->u.sval); break;
case FcOpMatrix:
printf ("[");
FcExprPrint (expr->u.mexpr->xx);
printf (" ");
FcExprPrint (expr->u.mexpr->xy);
printf ("; ");
FcExprPrint (expr->u.mexpr->yx);
printf (" ");
FcExprPrint (expr->u.mexpr->yy);
printf ("]");
break;
case FcOpRange: break;
2002-02-15 00:34:13 +01:00
case FcOpBool: printf ("%s", expr->u.bval ? "true" : "false"); break;
case FcOpCharSet: printf ("charset\n"); break;
case FcOpLangSet:
printf ("langset:");
FcLangSetPrint(expr->u.lval);
printf ("\n");
break;
case FcOpNil: printf ("nil\n"); break;
case FcOpField: printf ("%s ", FcObjectName(expr->u.name.object));
switch ((int) expr->u.name.kind) {
case FcMatchPattern:
printf ("(pattern) ");
break;
case FcMatchFont:
printf ("(font) ");
break;
}
break;
case FcOpConst: printf ("%s", expr->u.constant); break;
2002-02-15 00:34:13 +01:00
case FcOpQuest:
FcExprPrint (expr->u.tree.left);
printf (" quest ");
FcExprPrint (expr->u.tree.right->u.tree.left);
printf (" colon ");
FcExprPrint (expr->u.tree.right->u.tree.right);
break;
case FcOpAssign:
case FcOpAssignReplace:
case FcOpPrependFirst:
case FcOpPrepend:
case FcOpAppend:
case FcOpAppendLast:
2002-02-15 00:34:13 +01:00
case FcOpOr:
case FcOpAnd:
case FcOpEqual:
case FcOpNotEqual:
case FcOpLess:
case FcOpLessEqual:
case FcOpMore:
case FcOpMoreEqual:
case FcOpContains:
case FcOpListing:
case FcOpNotContains:
2002-02-15 00:34:13 +01:00
case FcOpPlus:
case FcOpMinus:
case FcOpTimes:
case FcOpDivide:
case FcOpComma:
2002-02-15 00:34:13 +01:00
FcExprPrint (expr->u.tree.left);
printf (" ");
switch (FC_OP_GET_OP (expr->op)) {
case FcOpAssign: printf ("Assign"); break;
case FcOpAssignReplace: printf ("AssignReplace"); break;
case FcOpPrependFirst: printf ("PrependFirst"); break;
case FcOpPrepend: printf ("Prepend"); break;
case FcOpAppend: printf ("Append"); break;
case FcOpAppendLast: printf ("AppendLast"); break;
2002-02-15 00:34:13 +01:00
case FcOpOr: printf ("Or"); break;
case FcOpAnd: printf ("And"); break;
case FcOpEqual: printf ("Equal"); FcOpFlagsPrint (expr->op); break;
case FcOpNotEqual: printf ("NotEqual"); FcOpFlagsPrint (expr->op); break;
2002-02-15 00:34:13 +01:00
case FcOpLess: printf ("Less"); break;
case FcOpLessEqual: printf ("LessEqual"); break;
case FcOpMore: printf ("More"); break;
case FcOpMoreEqual: printf ("MoreEqual"); break;
case FcOpContains: printf ("Contains"); break;
case FcOpListing: printf ("Listing"); FcOpFlagsPrint (expr->op); break;
case FcOpNotContains: printf ("NotContains"); break;
2002-02-15 00:34:13 +01:00
case FcOpPlus: printf ("Plus"); break;
case FcOpMinus: printf ("Minus"); break;
case FcOpTimes: printf ("Times"); break;
case FcOpDivide: printf ("Divide"); break;
case FcOpComma: printf ("Comma"); break;
2002-02-15 00:34:13 +01:00
default: break;
}
printf (" ");
FcExprPrint (expr->u.tree.right);
break;
case FcOpNot:
printf ("Not ");
FcExprPrint (expr->u.tree.left);
break;
case FcOpFloor:
printf ("Floor ");
FcExprPrint (expr->u.tree.left);
break;
case FcOpCeil:
printf ("Ceil ");
FcExprPrint (expr->u.tree.left);
break;
case FcOpRound:
printf ("Round ");
FcExprPrint (expr->u.tree.left);
break;
case FcOpTrunc:
printf ("Trunc ");
FcExprPrint (expr->u.tree.left);
break;
case FcOpInvalid: printf ("Invalid"); break;
2002-02-15 00:34:13 +01:00
}
}
void
FcTestPrint (const FcTest *test)
2002-02-15 00:34:13 +01:00
{
switch (test->kind) {
case FcMatchPattern:
printf ("pattern ");
break;
case FcMatchFont:
printf ("font ");
break;
case FcMatchScan:
printf ("scan ");
break;
}
2002-02-15 00:34:13 +01:00
switch (test->qual) {
case FcQualAny:
printf ("any ");
break;
case FcQualAll:
printf ("all ");
break;
case FcQualFirst:
printf ("first ");
break;
case FcQualNotFirst:
printf ("not_first ");
break;
2002-02-15 00:34:13 +01:00
}
printf ("%s ", FcObjectName (test->object));
2002-02-15 00:34:13 +01:00
FcOpPrint (test->op);
printf (" ");
FcExprPrint (test->expr);
printf ("\n");
}
void
FcEditPrint (const FcEdit *edit)
2002-02-15 00:34:13 +01:00
{
printf ("Edit %s ", FcObjectName (edit->object));
2002-02-15 00:34:13 +01:00
FcOpPrint (edit->op);
printf (" ");
FcExprPrint (edit->expr);
}
void
FcSubstPrint (const FcSubst *subst)
2002-02-15 00:34:13 +01:00
{
FcEdit *e;
FcTest *t;
2010-04-12 18:18:50 +02:00
2002-02-15 00:34:13 +01:00
printf ("match\n");
for (t = subst->test; t; t = t->next)
{
printf ("\t");
FcTestPrint (t);
}
printf ("edit\n");
for (e = subst->edit; e; e = e->next)
{
printf ("\t");
FcEditPrint (e);
printf (";\n");
}
printf ("\n");
}
void
FcFontSetPrint (const FcFontSet *s)
2002-02-15 00:34:13 +01:00
{
int i;
printf ("FontSet %d of %d\n", s->nfont, s->sfont);
for (i = 0; i < s->nfont; i++)
{
printf ("Font %d ", i);
FcPatternPrint (s->fonts[i]);
}
}
int FcDebugVal;
void
FcInitDebug (void)
2002-02-15 00:34:13 +01:00
{
char *e;
2002-02-15 00:34:13 +01:00
e = getenv ("FC_DEBUG");
if (e)
2002-02-15 00:34:13 +01:00
{
printf ("FC_DEBUG=%s\n", e);
FcDebugVal = atoi (e);
if (FcDebugVal < 0)
FcDebugVal = 0;
2002-02-15 00:34:13 +01:00
}
}
#define __fcdbg__
#include "fcaliastail.h"
#undef __fcdbg__