2 * fontconfig/src/fcrange.c
4 * Copyright © 2002 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the author(s) not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. The authors make no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
29 FcRangeCreateDouble (double begin, double end)
31 FcRange *ret = malloc (sizeof (FcRange));
43 FcRangeCreateInteger (FcChar32 begin, FcChar32 end)
45 FcRange *ret = malloc (sizeof (FcRange));
57 FcRangeDestroy (FcRange *range)
63 FcRangeCopy (const FcRange *range)
65 return FcRangeCreateDouble (range->begin, range->end);
69 FcRangeGetDouble(const FcRange *range, double *begin, double *end)
74 *begin = range->begin;
82 FcRangePromote (double v, FcValuePromotionBuffer *vbuf)
86 } FcRangePromotionBuffer;
87 FcRangePromotionBuffer *buf = (FcRangePromotionBuffer *) vbuf;
89 FC_ASSERT_STATIC (sizeof (FcRangePromotionBuffer) <= sizeof (FcValuePromotionBuffer));
97 FcRangeIsInRange (const FcRange *a, const FcRange *b)
99 return a->begin >= b->begin && a->end <= b->end;
103 FcRangeCompare (FcOp op, const FcRange *a, const FcRange *b)
107 return a->begin == b->begin && a->end == b->end;
110 return FcRangeIsInRange (a, b);
112 return a->begin != b->begin || a->end != b->end;
113 case FcOpNotContains:
114 return !FcRangeIsInRange (a, b);
116 return a->end < b->begin;
118 return a->end <= b->begin;
120 return a->begin > b->end;
122 return a->begin >= b->end;
130 FcRangeHash (const FcRange *r)
132 int b = (int) (r->begin * 100);
133 int e = (int) (r->end * 100);
135 return b ^ (b << 1) ^ (e << 9);
139 FcRangeSerializeAlloc (FcSerialize *serialize, const FcRange *r)
141 if (!FcSerializeAlloc (serialize, r, sizeof (FcRange)))
147 FcRangeSerialize (FcSerialize *serialize, const FcRange *r)
149 FcRange *r_serialize = FcSerializePtr (serialize, r);
153 memcpy (r_serialize, r, sizeof (FcRange));
159 #include "fcaliastail.h"