Bug 82582 - Warn if config is wrong
Summary: Warn if config is wrong
Status: RESOLVED MOVED
Alias: None
Product: fontconfig
Classification: Unclassified
Component: library (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: fontconfig-bugs
QA Contact: Behdad Esfahbod
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-13 20:46 UTC by Behdad Esfahbod
Modified: 2018-08-20 21:49 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Behdad Esfahbod 2014-08-13 20:46:32 UTC
I know we don't do full xml validation against the DTD, but at least, we should be able to catch many nonsensical configs, for example, someone trying this:

<match target="font">
    <or>
      <test name="family" compare="contains">
        <string>MYingHeiB5HK</string>
      </test>
      <test name="family" compare="contains">
        <string>MYingHeiGB18030</string>
      </test>
      <test name="family" compare="contains">
        <string>MSung GB18030</string>
      </test>
      <test name="family" compare="contains">
        <string>MSung B5HK</string>
      </test>
    </or>
    <!-- Turn on light auto-hint -->
    <!-- Turn off sub-pixel anti-aliasing -->
    <edit name="hinting" mode="assign"><bool>true</bool></edit>
    <edit name="autohint" mode="assign"><bool>true</bool></edit>
    <edit name="hintstyle" mode="assign"><const>hintslight</const></edit>
    <edit name="antialias" mode="assign"><bool>true</bool></edit>
    <edit name="rgba" mode="assign"><const>none</const></edit>
 </match>

The problem is, <or> doesn't go in <match>, and <test> doesn't go in <or>.  It just edits the pattern unconditionally! 

I *think* the correct way to write it is:

 <match target="font"> 
    <test name="family" compare="contains"> 
      <or> 
        <string>MYingHeiB5HK</string> 
        <string>MYingHeiGB18030</string> 
        <string>MSung GB18030</string> 
        <string>MSung B5HK</string> 
      </or> 
    </test> 

I hear in the past (with 2.7.x), this used to work:

<match target="font">
   <test name="family" compare="contains">
        <string>MYingHeiB5HK</string>
        <string>MYingHeiGB18030</string>
        <string>MSung GB18030</string>
        <string>MSung B5HK</string>
    </test>
    <!-- Turn on light auto-hint -->
    <!-- Turn off sub-pixel anti-aliasing -->
    <edit name="hinting" mode="assign"><bool>true</bool></edit>
    <edit name="autohint" mode="assign"><bool>true</bool></edit>
    <edit name="hintstyle" mode="assign"><const>hintslight</const></edit>
    <edit name="antialias" mode="assign"><bool>true</bool></edit>
    <edit name="rgba" mode="assign"><const>none</const></edit>
 </match>

but with 2.11.x started warning about multiple strings in <test>...
Comment 1 Jungshik Shin 2014-08-13 22:56:34 UTC
<match target="font"> 
    <test name="family" compare="contains"> 
      <or> 
        <string>MYingHeiB5HK</string> 
        <string>MYingHeiGB18030</string> 
        <string>MSung GB18030</string> 
        <string>MSung B5HK</string> 
      </or> 
    </test> 
    <edit ....... </edit>
</match>

The above doesn't give any warning. Nor did it affect other fonts (that are not listed in <test>) but <edit> is not applied to the fonts listed in <test>. 

Replacing the nested <test> as shown below works but I got a warning that 'test does not have a name'. 

<test>
    <or>
      <test name=...>
      <test name=...>
    </or>


The old form (that worked in 2.7.x) still works even though I got a warning about 'multiple values in test'. 

I also tried the old expression with 'qual="any"' added. It works as intended (that is, for any of the 4 fonts listed, <edit> is applied), but gave me the same warning about 'multiple values in test'. 

   <test name="family" compare="contains" qual="any">
        <string>MYingHeiB5HK</string>
        <string>MYingHeiGB18030</string>
        <string>MSung GB18030</string>
        <string>MSung B5HK</string>
    </test>
Comment 2 Jungshik Shin 2014-08-13 23:27:46 UTC
> Replacing the nested <test> as shown below works but I got a warning 
> that 'test does not have a name'. 

I was wrong about the following form. This one does not work properly because <edit>'s are applied not only to the 4 fonts listed but also to other fonts as well. 

<test>
    <or>
      <test name=...>
      <test name=...>
    </or>

So, at the moment, the only way that works for me is an old expression (2.7.x expression) even though it emits a scary warning message.
Comment 3 Akira TAGOH 2014-08-14 08:22:35 UTC
(In reply to comment #0)
> I *think* the correct way to write it is:
> 
>  <match target="font"> 
>     <test name="family" compare="contains"> 
>       <or> 
>         <string>MYingHeiB5HK</string> 
>         <string>MYingHeiGB18030</string> 
>         <string>MSung GB18030</string> 
>         <string>MSung B5HK</string> 
>       </or> 
>     </test> 

That doesn't even work. the required value types to test depends on the value of the "name". at the above example, string, and sometimes integer, boolean etc. but <or> always returns a boolean. so that fails.
I think too it is the way to go sensuously though, then the kind of the boolean operators may needs to be fixed to work as <test> similarly. the current implementation for them is really useless.

> I hear in the past (with 2.7.x), this used to work:
> 
> <match target="font">
>    <test name="family" compare="contains">
>         <string>MYingHeiB5HK</string>
>         <string>MYingHeiGB18030</string>
>         <string>MSung GB18030</string>
>         <string>MSung B5HK</string>
>     </test>
>     <!-- Turn on light auto-hint -->
>     <!-- Turn off sub-pixel anti-aliasing -->
>     <edit name="hinting" mode="assign"><bool>true</bool></edit>
>     <edit name="autohint" mode="assign"><bool>true</bool></edit>
>     <edit name="hintstyle" mode="assign"><const>hintslight</const></edit>
>     <edit name="antialias" mode="assign"><bool>true</bool></edit>
>     <edit name="rgba" mode="assign"><const>none</const></edit>
>  </match>
> 
> but with 2.11.x started warning about multiple strings in <test>...

See Bug#33644.
Comment 4 Behdad Esfahbod 2014-08-14 16:14:44 UTC
I see...

I think we should update the DTD to allow <or> around tests, not the other way around...  Lets think a bit more about it though.
Comment 5 Jungshik Shin 2014-08-14 22:05:45 UTC
In the meantime, http://lists.freedesktop.org/archives/fontconfig/2014-August/005298.html has two ways to achieve what I want to do.
Comment 6 Jungshik Shin 2018-05-18 22:25:26 UTC
I assume that this issue is still outstanding in the latest release.
Comment 7 GitLab Migration User 2018-08-20 21:49:06 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/fontconfig/fontconfig/issues/65.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.