
만약 내가 원한다면송나라언제흑체 또는 데자뷰 산스요구 사항: 이 구성은 잘 작동합니다.
<match target="pattern">
<test name="family"><string>Helvetica</string></test>
<edit binding="strong" mode="prepend" name="family">
<string>Arial</string>
</edit>
</match>
<match target="pattern">
<test name="family"><string>DejaVu Sans</string></test>
<edit binding="strong" mode="prepend" name="family">
<string>Arial</string>
</edit>
</match>
빠른 테스트:
$ echo Terminus Helvetica | xargs -n1 fc-match
ter-x12n.pcf.gz: "Terminus" "Regular"
arial.ttf: "Arial" "Regular"
하지만 너무 깁니다. Fontconfig 매뉴얼에는 <or>
요소가 언급되어 있지만 올바르게 사용하는 방법에 대한 예가 부족합니다. github에서 검색해봤는데
https://github.com/search?q=match+test+or+extension%3Aconf, 이는 다음과 매우 유사한 여러 가지 예를 반환합니다.
<match target="font">
<or>
<test name="family"><string>Nasu</string></test>
<test name="family"><string>NasuM</string></test>
</or>
<edit name="autohint"><bool>false</bool></edit>
</match>
불행히도, 순진하게 내 구성을 다음과 같이 다시 작성하면
<match target="pattern">
<or>
<test name="family"><string>Helvetica</string></test>
<test name="family"><string>DejaVu Sans</string></test>
</or>
<edit binding="strong" mode="prepend" name="family">
<string>Arial</string>
</edit>
</match>
그러면 모든 일치 항목이 중단됩니다.
$ echo Terminus Helvetica | xargs -n1 fc-match
arial.ttf: "Arial" "Regular"
arial.ttf: "Arial" "Regular"
답변1
안타깝게도 <match>
일치시키려는 각 성에 대해 전체 요소를 반복하는 것보다 더 나은 솔루션은 없습니다. 이 내용은 Fonts-conf(5) 매뉴얼 페이지에 설명되어 있습니다.
<--
The example of the requirements of OR operator;
If the 'family' contains 'Courier New' OR 'Courier'
add 'monospace' as the alternative
-->
<match target="pattern">
<test name="family" compare="eq">
<string>Courier New</string>
</test>
<edit name="family" mode="prepend">
<string>monospace</string>
</edit>
</match>
<match target="pattern">
<test name="family" compare="eq">
<string>Courier</string>
</test>
<edit name="family" mode="prepend">
<string>monospace</string>
</edit>
</match>
보고 있다글꼴 구성 버그 #33644, 누군가 요소 <string>
내의 여러 요소에 대한 규칙이 <test>
예상대로 작동하지 않는다고 불평했습니다. 규칙은 귀하의 규칙과 매우 유사하며 다음과 같습니다.
<match target="pattern"> <test name="family"> <string>Helvetica</string> <string>DejaVu Sans</string> </test> <edit binding="strong" mode="prepend" name="family"> <string>Arial</string> </edit> </match>
이러한 규칙의 문제점은 규칙에 언급된 값이 패턴에 두 개 이상 존재할 경우 해당 값이 패턴에서 다른 일치하는 값 뒤에 나타나더라도 규칙은 이전에 규칙에 지정된 값과 일치한다는 것입니다. ; 그러면 mode="prepend"
원하는 효과를 얻지 못할 수도 있습니다. 귀하의 예를 들어:
- 패턴에 "Helvetica, DejaVu Sans"가 포함된 경우 규칙은 "Helvetica"와 일치하여 "Arial, Helvetica, DejaVu Sans"를 생성합니다.
- 패턴에 "DejaVu Sans, Helvetica"가 포함된 경우 규칙은 여전히 "Helvetica"와 일치하고 결과적으로 "DejaVu Sans, Arial, Helvetica"가 되므로 Arial은 필요에 따라 선택되지 않습니다.
별도의 규칙을 사용하는 경우 두 규칙이 두 사례 모두에 적용되며 "Arial, Helvetica, Arial, DejaVu Sans" 또는 "Arial, DejaVu Sans, Arial, Helvetica"가 표시되므로 두 경우 모두 Arial 사례가 선택됩니다. 상황.
이 버그 보고서에 응답하세요.<test>
구성에서 여러 값을 가진 요소가 발견되면 경고를 인쇄하도록 글꼴 구성이 변경되었습니다.이므로 기능이 작동하더라도 사용하면 안 됩니다.
요소 의 경우 <or>
두 개 이상의 부울 값을 가져와 부울 값을 반환하는 표현식에만 작동하므로 작업에 적합하지 않습니다.