revert between 56095 -> 55830 in arch
[AROS.git] / rom / graphics / weightamatch.c
blob2e18350bea8109da8b1f9358f15a690ad7a961ad
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include "graphics_intern.h"
9 #include <stdlib.h>
11 /*****************************************************************************
13 NAME */
14 #include <clib/graphics_protos.h>
16 AROS_LH3(WORD, WeighTAMatch,
18 /* SYNOPSIS */
19 AROS_LHA(const struct TextAttr *, reqTextAttr, A0),
20 AROS_LHA(const struct TextAttr *, targetTextAttr, A1),
21 AROS_LHA(struct TagItem *, targetTags, A2),
23 /* LOCATION */
24 struct GfxBase *, GfxBase, 134, Graphics)
26 /* FUNCTION
27 Determines how well two font descriptions match.
29 INPUTS
30 reqTextAttr - the required textattr.
31 targetTextAttr - textattr of potential match.
32 targetTags - tags for the targetTextAttr.
34 RESULT
35 A weight number which measures how well the TextAttrs
36 match. The weight may vary from 0 (no match) to
37 MAXFONTMATCHWEIGHT (perfect match).
39 NOTES
41 EXAMPLE
43 BUGS
44 Does not yet take tags into account.
46 SEE ALSO
48 INTERNALS
51 HISTORY
52 27-11-96 digulla automatically created from
53 graphics_lib.fd and clib/graphics_protos.h
55 *****************************************************************************/
57 AROS_LIBFUNC_INIT
59 WORD matchweight = MAXFONTMATCHWEIGHT;
60 WORD sizematch = 0; /* for temporary keeping data */
61 UWORD sizediff;
63 /* Compare font flags */
65 /* No match if req is designed and target not */
66 if ((reqTextAttr->ta_Flags & FPF_DESIGNED) && ! (targetTextAttr->ta_Flags & (FPF_DESIGNED | FPF_DISKFONT)))
67 return 0;
69 /* No match if REVPATH is not the same, ignore other flags */
70 if ((reqTextAttr->ta_Flags ^ targetTextAttr->ta_Flags) & FPF_REVPATH)
71 return 0;
74 /* Compare font style */
75 if ((reqTextAttr->ta_Style & FSF_UNDERLINED) && !(targetTextAttr->ta_Style & FSF_UNDERLINED))
76 matchweight &= ~(1<<2);
77 if (!(reqTextAttr->ta_Style & FSF_UNDERLINED) && (targetTextAttr->ta_Style & FSF_UNDERLINED))
78 matchweight &= ~(1<<11);
80 if ((reqTextAttr->ta_Style & FSF_BOLD) && !(targetTextAttr->ta_Style & FSF_BOLD))
81 matchweight &= ~(1<<3);
82 if (!(reqTextAttr->ta_Style & FSF_BOLD) && (targetTextAttr->ta_Style & FSF_BOLD))
83 matchweight &= ~(1<<9);
85 if ((reqTextAttr->ta_Style & FSF_ITALIC) && !(targetTextAttr->ta_Style & FSF_ITALIC))
86 matchweight &= ~(1<<4);
87 if (!(reqTextAttr->ta_Style & FSF_ITALIC) && (targetTextAttr->ta_Style & FSF_ITALIC))
88 matchweight &= ~(1<<10);
90 /* Now subtract a value depending on the size difference */
92 sizediff = abs((WORD)reqTextAttr->ta_YSize - (WORD)targetTextAttr->ta_YSize);
94 if (sizediff > 511)
95 return 0;
97 if (reqTextAttr->ta_YSize < targetTextAttr->ta_YSize)
98 sizematch = sizediff << 7;
99 else
100 sizematch = sizediff << 5;
102 if (sizematch > matchweight)
103 matchweight = 0;
104 else
105 matchweight -= sizematch;
107 return matchweight;
109 AROS_LIBFUNC_EXIT
110 } /* WeighTAMatch */