lewp_css/domain/at_rules/font_face/font_url_source.rs
1// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.
3
4use {
5 crate::domain::SpecifiedUrl,
6 cssparser::{serialize_string, ToCss},
7 std::fmt,
8};
9
10/// A `UrlSource` represents a font-face source that has been specified with a `url()` function.
11///
12/// <https://drafts.csswg.org/css-fonts/#src-desc>
13#[derive(Clone, Debug, Eq, PartialEq)]
14pub struct FontUrlSource {
15 /// The specified url.
16 pub url: SpecifiedUrl,
17
18 /// The format hints specified with the `format()` function.
19 /// Examples are "truetype", "opentype" and "woff"
20 pub format_hints: Vec<String>,
21}
22
23impl ToCss for FontUrlSource {
24 fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
25 self.url.to_css(dest)?;
26
27 if !self.format_hints.is_empty() {
28 dest.write_str(" format(")?;
29 let mut formatHintsIterator = self.format_hints.iter();
30 serialize_string(formatHintsIterator.next().unwrap(), dest)?;
31 for formatHint in formatHintsIterator {
32 dest.write_char(',')?;
33 serialize_string(formatHint, dest)?;
34 }
35 dest.write_char(')')?;
36 }
37
38 Ok(())
39 }
40}