New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / graphics / weightamatch.c
blobb0f76b808df8770727f3ebde7b9cd9754b68585e
1 /*
2 Copyright © 1995-2001, 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(struct TextAttr *, reqTextAttr, A0),
20 AROS_LHA(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
58 AROS_LIBBASE_EXT_DECL(struct GfxBase *,GfxBase)
60 WORD matchweight = MAXFONTMATCHWEIGHT;
61 WORD sizematch = 0; /* for temporary keeping data */
62 UWORD sizediff;
64 /* Compare font flags */
66 /* No match if req is designed and target not */
67 if ((reqTextAttr->ta_Flags & FPF_DESIGNED) && ! (targetTextAttr->ta_Flags & (FPF_DESIGNED | FPF_DISKFONT)))
68 return 0;
70 /* No match if REVPATH is not the same, ignore other flags */
71 if ((reqTextAttr->ta_Flags ^ targetTextAttr->ta_Flags) & FPF_REVPATH)
72 return 0;
75 /* Compare font style */
76 if ((reqTextAttr->ta_Style & FSF_UNDERLINED) && !(targetTextAttr->ta_Style & FSF_UNDERLINED))
77 matchweight &= ~(1<<2);
78 if (!(reqTextAttr->ta_Style & FSF_UNDERLINED) && (targetTextAttr->ta_Style & FSF_UNDERLINED))
79 matchweight &= ~(1<<11);
81 if ((reqTextAttr->ta_Style & FSF_BOLD) && !(targetTextAttr->ta_Style & FSF_BOLD))
82 matchweight &= ~(1<<3);
83 if (!(reqTextAttr->ta_Style & FSF_BOLD) && (targetTextAttr->ta_Style & FSF_BOLD))
84 matchweight &= ~(1<<9);
86 if ((reqTextAttr->ta_Style & FSF_ITALIC) && !(targetTextAttr->ta_Style & FSF_ITALIC))
87 matchweight &= ~(1<<4);
88 if (!(reqTextAttr->ta_Style & FSF_ITALIC) && (targetTextAttr->ta_Style & FSF_ITALIC))
89 matchweight &= ~(1<<10);
91 /* Now subtract a value depending on the size difference */
93 sizediff = abs((WORD)reqTextAttr->ta_YSize - (WORD)targetTextAttr->ta_YSize);
95 if (sizediff > 511)
96 return 0;
98 if (reqTextAttr->ta_YSize < targetTextAttr->ta_YSize)
99 sizematch = sizediff << 7;
100 else
101 sizematch = sizediff << 5;
103 if (sizematch > matchweight)
104 matchweight = 0;
105 else
106 matchweight -= sizematch;
108 return matchweight;
110 AROS_LIBFUNC_EXIT
111 } /* WeighTAMatch */