Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
fontconfig
fontconfig
Commits
706535e1
Commit
706535e1
authored
Jan 03, 2018
by
Behdad Esfahbod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add FcWeightTo/FromOpenTypeDouble()
No idea why I didn't add these as double to begin with.
parent
97898b11
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
24 deletions
+64
-24
doc/fcweight.fncs
doc/fcweight.fncs
+32
-10
fontconfig/fontconfig.h
fontconfig/fontconfig.h
+6
-0
src/fcfreetype.c
src/fcfreetype.c
+8
-8
src/fcweight.c
src/fcweight.c
+18
-6
No files found.
doc/fcweight.fncs
View file @
706535e1
...
...
@@ -19,18 +19,41 @@
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
@RET@
int
@FUNC@ FcWeightFromOpenType
@TYPE1@
int
@ARG1@ ot_weight
@RET@
double
@FUNC@ FcWeightFromOpenType
Double
@TYPE1@
double
@ARG1@ ot_weight
@PURPOSE@ Convert from OpenType weight values to fontconfig ones
@DESC@
<function>FcWeightFromOpenType</function> returns an
integer
value
to use with FC_WEIGHT, from an
integer
in the 1..1000 range, resembling
<function>FcWeightFromOpenType
Double
</function> returns an
double
value
to use with FC_WEIGHT, from an
double
in the 1..1000 range, resembling
the numbers from OpenType specification's OS/2 usWeight numbers, which
are also similar to CSS font-weight numbers. If input is negative,
zero, or greater than 1000, returns -1. This function linearly
int
erpolates
zero, or greater than 1000, returns -1. This function linearly
double
erpolates
between various FC_WEIGHT_* constants. As such, the returned value does not
necessarily match any of the predefined constants.
@SINCE@ 2.12.92
@@
@RET@ double
@FUNC@ FcWeightToOpenTypeDouble
@TYPE1@ double @ARG1@ ot_weight
@PURPOSE@ Convert from fontconfig weight values to OpenType ones
@DESC@
<function>FcWeightToOpenTypeDouble</function> is the inverse of
<function>FcWeightFromOpenType</function>. If the input is less than
FC_WEIGHT_THIN or greater than FC_WEIGHT_EXTRABLACK, returns -1. Otherwise
returns a number in the range 1 to 1000.
@SINCE@ 2.12.92
@@
@RET@ int
@FUNC@ FcWeightFromOpenType
@TYPE1@ int @ARG1@ ot_weight
@PURPOSE@ Convert from OpenType weight values to fontconfig ones
@DESC@
<function>FcWeightFromOpenType</function> is like
<function>FcWeightFromOpenTypeDouble</function> but with integer arguments.
Use the other function instead.
@SINCE@ 2.11.91
@@
...
...
@@ -39,9 +62,8 @@ necessarily match any of the predefined constants.
@TYPE1@ int @ARG1@ ot_weight
@PURPOSE@ Convert from fontconfig weight values to OpenType ones
@DESC@
<function>FcWeightToOpenType</function> is the inverse of
<function>FcWeightFromOpenType</function>. If the input is less than
FC_WEIGHT_THIN or greater than FC_WEIGHT_EXTRABLACK, returns -1. Otherwise
returns a number in the range 1 to 1000.
<function>FcWeightToOpenType</function> is like
<function>FcWeightToOpenTypeDouble</function> but with integer arguments.
Use the other function instead.
@SINCE@ 2.11.91
@@
fontconfig/fontconfig.h
View file @
706535e1
...
...
@@ -966,9 +966,15 @@ FcRangeGetDouble(const FcRange *range, double *begin, double *end);
FcPublic
int
FcWeightFromOpenType
(
int
ot_weight
);
FcPublic
double
FcWeightFromOpenTypeDouble
(
double
ot_weight
);
FcPublic
int
FcWeightToOpenType
(
int
fc_weight
);
FcPublic
double
FcWeightToOpenTypeDouble
(
double
fc_weight
);
/* fcstr.c */
FcPublic
FcChar8
*
...
...
src/fcfreetype.c
View file @
706535e1
...
...
@@ -1171,7 +1171,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
{
FcPattern
*
pat
;
int
slant
=
-
1
;
int
weight
=
-
1
;
double
weight
=
-
1
;
int
width
=
-
1
;
FcBool
decorative
=
FcFalse
;
FcBool
variable
=
FcFalse
;
...
...
@@ -1264,8 +1264,8 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
{
case
FT_MAKE_TAG
(
'w'
,
'g'
,
'h'
,
't'
):
elt
=
FC_WEIGHT
;
min_value
=
FcWeightFromOpenType
(
min_value
);
max_value
=
FcWeightFromOpenType
(
max_value
);
min_value
=
FcWeightFromOpenType
Double
(
min_value
);
max_value
=
FcWeightFromOpenType
Double
(
max_value
);
variable_weight
=
FcTrue
;
weight
=
0
;
/* To stop looking for weight. */
break
;
...
...
@@ -1694,15 +1694,15 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
{
/* Work around bad values by cleaning them up before
* multiplying by weight_mult. */
weight
=
FcWeightToOpenType
(
FcWeightFromOpenType
(
weight
));
weight
=
FcWeightToOpenType
Double
(
FcWeightFromOpenType
Double
(
weight
));
}
weight
=
FcWeightFromOpenType
((
int
)
(
weight
*
weight_mult
+
.
5
));
weight
=
FcWeightFromOpenType
Double
((
int
)
(
weight
*
weight_mult
+
.
5
));
if
((
FcDebug
()
&
FC_DBG_SCANV
)
&&
weight
!=
-
1
)
printf
(
"
\t
os2 weight class %d multiplier %g maps to weight %
d
\n
"
,
printf
(
"
\t
os2 weight class %d multiplier %g maps to weight %
g
\n
"
,
os2
->
usWeightClass
,
weight_mult
,
weight
);
/* TODO:
* Add FcWidthFromOpenType and FcWidthToOpenType,
* Add FcWidthFromOpenType
Double
and FcWidthToOpenType
Double
,
* and apply width_mult post-conversion? */
switch
((
int
)
(
os2
->
usWidthClass
*
width_mult
+
.
5
))
{
case
1
:
width
=
FC_WIDTH_ULTRACONDENSED
;
break
;
...
...
@@ -1893,7 +1893,7 @@ FcFreeTypeQueryFaceInternal (const FT_Face face,
if
(
!
FcPatternAddInteger
(
pat
,
FC_SLANT
,
slant
))
goto
bail1
;
if
(
!
variable_weight
&&
!
FcPatternAdd
Integer
(
pat
,
FC_WEIGHT
,
weight
))
if
(
!
variable_weight
&&
!
FcPatternAdd
Double
(
pat
,
FC_WEIGHT
,
weight
))
goto
bail1
;
if
(
!
variable_width
&&
!
FcPatternAddInteger
(
pat
,
FC_WIDTH
,
width
))
...
...
src/fcweight.c
View file @
706535e1
...
...
@@ -41,7 +41,7 @@ static const struct {
{
1000
,
FC_WEIGHT_EXTRABLACK
},
};
static
int
lerp
(
int
x
,
int
x1
,
int
x2
,
int
y1
,
int
y2
)
static
double
lerp
(
double
x
,
int
x1
,
int
x2
,
int
y1
,
int
y2
)
{
int
dx
=
x2
-
x1
;
int
dy
=
y2
-
y1
;
...
...
@@ -49,8 +49,8 @@ static int lerp(int x, int x1, int x2, int y1, int y2)
return
y1
+
(
dy
*
(
x
-
x1
)
+
dx
/
2
)
/
dx
;
}
int
FcWeightFromOpenType
(
int
ot_weight
)
double
FcWeightFromOpenType
Double
(
double
ot_weight
)
{
int
i
;
...
...
@@ -63,7 +63,7 @@ FcWeightFromOpenType (int ot_weight)
/* WPF Font Selection Model says do "ot_weight *= 100",
* but Greg Hitchcock revealed that GDI had a mapping
* reflected below: */
switch
(
ot_weight
)
{
switch
(
(
int
)
ot_weight
)
{
case
1
:
ot_weight
=
80
;
break
;
case
2
:
ot_weight
=
160
;
break
;
case
3
:
ot_weight
=
240
;
break
;
...
...
@@ -87,8 +87,8 @@ FcWeightFromOpenType (int ot_weight)
return
lerp
(
ot_weight
,
map
[
i
-
1
].
ot
,
map
[
i
].
ot
,
map
[
i
-
1
].
fc
,
map
[
i
].
fc
);
}
int
FcWeightToOpenType
(
int
fc_weight
)
double
FcWeightToOpenType
Double
(
double
fc_weight
)
{
int
i
;
if
(
fc_weight
<
0
||
fc_weight
>
FC_WEIGHT_EXTRABLACK
)
...
...
@@ -104,6 +104,18 @@ FcWeightToOpenType (int fc_weight)
return
lerp
(
fc_weight
,
map
[
i
-
1
].
fc
,
map
[
i
].
fc
,
map
[
i
-
1
].
ot
,
map
[
i
].
ot
);
}
int
FcWeightFromOpenType
(
int
ot_weight
)
{
return
FcWeightFromOpenTypeDouble
(
ot_weight
)
+
.
5
;
}
int
FcWeightToOpenType
(
int
fc_weight
)
{
return
FcWeightToOpenTypeDouble
(
fc_weight
)
+
.
5
;
}
#define __fcweight__
#include "fcaliastail.h"
#undef __fcweight__
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment