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)
64 FcRangeCopy (const FcRange *range)
66 return FcRangeCreateDouble (range->begin, range->end);
70 FcRangeGetDouble(const FcRange *range, double *begin, double *end)
75 *begin = range->begin;
83 FcRangePromote (double v, FcValuePromotionBuffer *vbuf)
87 } FcRangePromotionBuffer;
88 FcRangePromotionBuffer *buf = (FcRangePromotionBuffer *) vbuf;
90 FC_ASSERT_STATIC (sizeof (FcRangePromotionBuffer) <= sizeof (FcValuePromotionBuffer));
98 FcRangeIsInRange (const FcRange *a, const FcRange *b)
100 return a->begin >= b->begin && a->end <= b->end;
104 FcRangeCompare (FcOp op, const FcRange *a, const FcRange *b)
108 return a->begin == b->begin && a->end == b->end;
111 return FcRangeIsInRange (a, b);
113 return a->begin != b->begin || a->end != b->end;
114 case FcOpNotContains:
115 return !FcRangeIsInRange (a, b);
117 return a->end < b->begin;
119 return a->end <= b->begin;
121 return a->begin > b->end;
123 return a->begin >= b->end;
131 FcRangeHash (const FcRange *r)
133 int b = (int) (r->begin * 100);
134 int e = (int) (r->end * 100);
136 return b ^ (b << 1) ^ (e << 9);
140 FcRangeSerializeAlloc (FcSerialize *serialize, const FcRange *r)
142 if (!FcSerializeAlloc (serialize, r, sizeof (FcRange)))
148 FcRangeSerialize (FcSerialize *serialize, const FcRange *r)
150 FcRange *r_serialize = FcSerializePtr (serialize, r);
154 memcpy (r_serialize, r, sizeof (FcRange));
160 #include "fcaliastail.h"