Skip to content

Commit

Permalink
Added support for the "font" Top-Level Media Type (https://tools.ietf…
Browse files Browse the repository at this point in the history
….org/html/rfc8081)

RELNOTES=`net`: Added support for "font" Top-Level Media Type

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=314193029
  • Loading branch information
sicter authored and netdpb committed Jun 2, 2020
1 parent abea458 commit 571cf66
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 20 deletions.
Expand Up @@ -192,6 +192,12 @@ public void testCreateAudioType() {
assertEquals("yams", newType.subtype());
}

public void testCreateFontType() {
MediaType newType = MediaType.createFontType("yams");
assertEquals("font", newType.type());
assertEquals("yams", newType.subtype());
}

public void testCreateImageType() {
MediaType newType = MediaType.createImageType("yams");
assertEquals("image", newType.type());
Expand Down
93 changes: 83 additions & 10 deletions android/guava/src/com/google/common/net/MediaType.java
Expand Up @@ -101,6 +101,7 @@ public final class MediaType {
private static final String IMAGE_TYPE = "image";
private static final String TEXT_TYPE = "text";
private static final String VIDEO_TYPE = "video";
private static final String FONT_TYPE = "font";

private static final String WILDCARD = "*";

Expand Down Expand Up @@ -141,6 +142,13 @@ private static MediaType addKnownType(MediaType mediaType) {
public static final MediaType ANY_VIDEO_TYPE = createConstant(VIDEO_TYPE, WILDCARD);
public static final MediaType ANY_APPLICATION_TYPE = createConstant(APPLICATION_TYPE, WILDCARD);

/**
* Wildcard matching any "font" top-level media type.
*
* @since NEXT
*/
public static final MediaType ANY_FONT_TYPE = createConstant(FONT_TYPE, WILDCARD);

/* text types */
public static final MediaType CACHE_MANIFEST_UTF_8 =
createConstantUtf8(TEXT_TYPE, "cache-manifest");
Expand Down Expand Up @@ -189,6 +197,7 @@ private static MediaType addKnownType(MediaType mediaType) {
*/
public static final MediaType VTT_UTF_8 = createConstantUtf8(TEXT_TYPE, "vtt");

/* image types */
/**
* <a href="https://en.wikipedia.org/wiki/BMP_file_format">Bitmap file format</a> ({@code bmp}
* files).
Expand Down Expand Up @@ -628,10 +637,9 @@ private static MediaType addKnownType(MediaType mediaType) {
public static final MediaType RTF_UTF_8 = createConstantUtf8(APPLICATION_TYPE, "rtf");

/**
* SFNT fonts (which includes <a href="http://en.wikipedia.org/wiki/TrueType/">TrueType</a> and <a
* href="http://en.wikipedia.org/wiki/OpenType/">OpenType</a> fonts). This is <a
* href="http://www.iana.org/assignments/media-types/application/font-sfnt">registered</a> with
* the IANA.
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares {@link #FONT_SFNT
* font/sfnt} to be the correct media type for SFNT, but this may be necessary in certain
* situations for compatibility.
*
* @since 17.0
*/
Expand Down Expand Up @@ -664,18 +672,18 @@ private static MediaType addKnownType(MediaType mediaType) {
public static final MediaType TAR = createConstant(APPLICATION_TYPE, "x-tar");

/**
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF) <a
* href="http://www.w3.org/TR/WOFF/">defined</a> by the W3C. This is <a
* href="http://www.iana.org/assignments/media-types/application/font-woff">registered</a> with
* the IANA.
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares {@link #FONT_WOFF
* font/woff} to be the correct media type for WOFF, but this may be necessary in certain
* situations for compatibility.
*
* @since 17.0
*/
public static final MediaType WOFF = createConstant(APPLICATION_TYPE, "font-woff");

/**
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF)
* version 2 <a href="https://www.w3.org/TR/WOFF2/">defined</a> by the W3C.
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares {@link #FONT_WOFF2
* font/woff2} to be the correct media type for WOFF2, but this may be necessary in certain
* situations for compatibility.
*
* @since 20.0
*/
Expand All @@ -695,6 +703,62 @@ private static MediaType addKnownType(MediaType mediaType) {

public static final MediaType ZIP = createConstant(APPLICATION_TYPE, "zip");

/* font types */

/**
* A collection of font outlines as defined by <a href="https://tools.ietf.org/html/rfc8081">RFC
* 8081</a>.
*
* @since NEXT
*/
public static final MediaType FONT_COLLECTION = createConstant(FONT_TYPE, "collection");

/**
* <a href="https://en.wikipedia.org/wiki/OpenType">Open Type Font Format</a> (OTF) as defined by
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a>.
*
* @since NEXT
*/
public static final MediaType FONT_OTF = createConstant(FONT_TYPE, "otf");

/**
* <a href="https://en.wikipedia.org/wiki/SFNT">Spline or Scalable Font Format</a> (SFNT). <a
* href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct media
* type for SFNT, but {@link #SFNT application/font-sfnt} may be necessary in certain situations
* for compatibility.
*
* @since NEXT
*/
public static final MediaType FONT_SFNT = createConstant(FONT_TYPE, "sfnt");

/**
* <a href="https://en.wikipedia.org/wiki/TrueType">True Type Font Format</a> (TTF) as defined by
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a>.
*
* @since NEXT
*/
public static final MediaType FONT_TTF = createConstant(FONT_TYPE, "ttf");

/**
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF). <a
* href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct media
* type for SFNT, but {@link #WOFF application/font-woff} may be necessary in certain situations
* for compatibility.
*
* @since NEXT
*/
public static final MediaType FONT_WOFF = createConstant(FONT_TYPE, "woff");

/**
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF2).
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct
* media type for SFNT, but {@link #WOFF2 application/font-woff2} may be necessary in certain
* situations for compatibility.
*
* @since NEXT
*/
public static final MediaType FONT_WOFF2 = createConstant(FONT_TYPE, "woff2");

private final String type;
private final String subtype;
private final ImmutableListMultimap<String, String> parameters;
Expand Down Expand Up @@ -931,6 +995,15 @@ static MediaType createAudioType(String subtype) {
return create(AUDIO_TYPE, subtype);
}

/**
* Creates a media type with the "font" type and the given subtype.
*
* @throws IllegalArgumentException if subtype is invalid
*/
static MediaType createFontType(String subtype) {
return create(FONT_TYPE, subtype);
}

/**
* Creates a media type with the "image" type and the given subtype.
*
Expand Down
5 changes: 5 additions & 0 deletions guava-gwt/test/com/google/common/net/MediaTypeTest_gwt.java
Expand Up @@ -28,6 +28,11 @@ public void testCreateAudioType() throws Exception {
testCase.testCreateAudioType();
}

public void testCreateFontType() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testCreateFontType();
}

public void testCreateImageType() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testCreateImageType();
Expand Down
6 changes: 6 additions & 0 deletions guava-tests/test/com/google/common/net/MediaTypeTest.java
Expand Up @@ -192,6 +192,12 @@ public void testCreateAudioType() {
assertEquals("yams", newType.subtype());
}

public void testCreateFontType() {
MediaType newType = MediaType.createFontType("yams");
assertEquals("font", newType.type());
assertEquals("yams", newType.subtype());
}

public void testCreateImageType() {
MediaType newType = MediaType.createImageType("yams");
assertEquals("image", newType.type());
Expand Down
93 changes: 83 additions & 10 deletions guava/src/com/google/common/net/MediaType.java
Expand Up @@ -101,6 +101,7 @@ public final class MediaType {
private static final String IMAGE_TYPE = "image";
private static final String TEXT_TYPE = "text";
private static final String VIDEO_TYPE = "video";
private static final String FONT_TYPE = "font";

private static final String WILDCARD = "*";

Expand Down Expand Up @@ -141,6 +142,13 @@ private static MediaType addKnownType(MediaType mediaType) {
public static final MediaType ANY_VIDEO_TYPE = createConstant(VIDEO_TYPE, WILDCARD);
public static final MediaType ANY_APPLICATION_TYPE = createConstant(APPLICATION_TYPE, WILDCARD);

/**
* Wildcard matching any "font" top-level media type.
*
* @since NEXT
*/
public static final MediaType ANY_FONT_TYPE = createConstant(FONT_TYPE, WILDCARD);

/* text types */
public static final MediaType CACHE_MANIFEST_UTF_8 =
createConstantUtf8(TEXT_TYPE, "cache-manifest");
Expand Down Expand Up @@ -189,6 +197,7 @@ private static MediaType addKnownType(MediaType mediaType) {
*/
public static final MediaType VTT_UTF_8 = createConstantUtf8(TEXT_TYPE, "vtt");

/* image types */
/**
* <a href="https://en.wikipedia.org/wiki/BMP_file_format">Bitmap file format</a> ({@code bmp}
* files).
Expand Down Expand Up @@ -628,10 +637,9 @@ private static MediaType addKnownType(MediaType mediaType) {
public static final MediaType RTF_UTF_8 = createConstantUtf8(APPLICATION_TYPE, "rtf");

/**
* SFNT fonts (which includes <a href="http://en.wikipedia.org/wiki/TrueType/">TrueType</a> and <a
* href="http://en.wikipedia.org/wiki/OpenType/">OpenType</a> fonts). This is <a
* href="http://www.iana.org/assignments/media-types/application/font-sfnt">registered</a> with
* the IANA.
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares {@link #FONT_SFNT
* font/sfnt} to be the correct media type for SFNT, but this may be necessary in certain
* situations for compatibility.
*
* @since 17.0
*/
Expand Down Expand Up @@ -664,18 +672,18 @@ private static MediaType addKnownType(MediaType mediaType) {
public static final MediaType TAR = createConstant(APPLICATION_TYPE, "x-tar");

/**
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF) <a
* href="http://www.w3.org/TR/WOFF/">defined</a> by the W3C. This is <a
* href="http://www.iana.org/assignments/media-types/application/font-woff">registered</a> with
* the IANA.
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares {@link #FONT_WOFF
* font/woff} to be the correct media type for WOFF, but this may be necessary in certain
* situations for compatibility.
*
* @since 17.0
*/
public static final MediaType WOFF = createConstant(APPLICATION_TYPE, "font-woff");

/**
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF)
* version 2 <a href="https://www.w3.org/TR/WOFF2/">defined</a> by the W3C.
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares {@link #FONT_WOFF2
* font/woff2} to be the correct media type for WOFF2, but this may be necessary in certain
* situations for compatibility.
*
* @since 20.0
*/
Expand All @@ -695,6 +703,62 @@ private static MediaType addKnownType(MediaType mediaType) {

public static final MediaType ZIP = createConstant(APPLICATION_TYPE, "zip");

/* font types */

/**
* A collection of font outlines as defined by <a href="https://tools.ietf.org/html/rfc8081">RFC
* 8081</a>.
*
* @since NEXT
*/
public static final MediaType FONT_COLLECTION = createConstant(FONT_TYPE, "collection");

/**
* <a href="https://en.wikipedia.org/wiki/OpenType">Open Type Font Format</a> (OTF) as defined by
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a>.
*
* @since NEXT
*/
public static final MediaType FONT_OTF = createConstant(FONT_TYPE, "otf");

/**
* <a href="https://en.wikipedia.org/wiki/SFNT">Spline or Scalable Font Format</a> (SFNT). <a
* href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct media
* type for SFNT, but {@link #SFNT application/font-sfnt} may be necessary in certain situations
* for compatibility.
*
* @since NEXT
*/
public static final MediaType FONT_SFNT = createConstant(FONT_TYPE, "sfnt");

/**
* <a href="https://en.wikipedia.org/wiki/TrueType">True Type Font Format</a> (TTF) as defined by
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a>.
*
* @since NEXT
*/
public static final MediaType FONT_TTF = createConstant(FONT_TYPE, "ttf");

/**
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF). <a
* href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct media
* type for SFNT, but {@link #WOFF application/font-woff} may be necessary in certain situations
* for compatibility.
*
* @since NEXT
*/
public static final MediaType FONT_WOFF = createConstant(FONT_TYPE, "woff");

/**
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF2).
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct
* media type for SFNT, but {@link #WOFF2 application/font-woff2} may be necessary in certain
* situations for compatibility.
*
* @since NEXT
*/
public static final MediaType FONT_WOFF2 = createConstant(FONT_TYPE, "woff2");

private final String type;
private final String subtype;
private final ImmutableListMultimap<String, String> parameters;
Expand Down Expand Up @@ -931,6 +995,15 @@ static MediaType createAudioType(String subtype) {
return create(AUDIO_TYPE, subtype);
}

/**
* Creates a media type with the "font" type and the given subtype.
*
* @throws IllegalArgumentException if subtype is invalid
*/
static MediaType createFontType(String subtype) {
return create(FONT_TYPE, subtype);
}

/**
* Creates a media type with the "image" type and the given subtype.
*
Expand Down

0 comments on commit 571cf66

Please sign in to comment.