diff --git a/android/guava-tests/test/com/google/common/net/MediaTypeTest.java b/android/guava-tests/test/com/google/common/net/MediaTypeTest.java
index 1276f97fe036..cec3cdd28cce 100644
--- a/android/guava-tests/test/com/google/common/net/MediaTypeTest.java
+++ b/android/guava-tests/test/com/google/common/net/MediaTypeTest.java
@@ -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());
diff --git a/android/guava/src/com/google/common/net/MediaType.java b/android/guava/src/com/google/common/net/MediaType.java
index 79f369824e37..8cf09c8057a0 100644
--- a/android/guava/src/com/google/common/net/MediaType.java
+++ b/android/guava/src/com/google/common/net/MediaType.java
@@ -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 = "*";
@@ -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");
@@ -189,6 +197,7 @@ private static MediaType addKnownType(MediaType mediaType) {
*/
public static final MediaType VTT_UTF_8 = createConstantUtf8(TEXT_TYPE, "vtt");
+ /* image types */
/**
* Bitmap file format ({@code bmp}
* files).
@@ -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 TrueType and OpenType fonts). This is registered with
- * the IANA.
+ * RFC 8081 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
*/
@@ -664,18 +672,18 @@ private static MediaType addKnownType(MediaType mediaType) {
public static final MediaType TAR = createConstant(APPLICATION_TYPE, "x-tar");
/**
- * Web Open Font Format (WOFF) defined by the W3C. This is registered with
- * the IANA.
+ * RFC 8081 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");
/**
- * Web Open Font Format (WOFF)
- * version 2 defined by the W3C.
+ * RFC 8081 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
*/
@@ -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 RFC
+ * 8081.
+ *
+ * @since NEXT
+ */
+ public static final MediaType FONT_COLLECTION = createConstant(FONT_TYPE, "collection");
+
+ /**
+ * Open Type Font Format (OTF) as defined by
+ * RFC 8081.
+ *
+ * @since NEXT
+ */
+ public static final MediaType FONT_OTF = createConstant(FONT_TYPE, "otf");
+
+ /**
+ * Spline or Scalable Font Format (SFNT). RFC 8081 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");
+
+ /**
+ * True Type Font Format (TTF) as defined by
+ * RFC 8081.
+ *
+ * @since NEXT
+ */
+ public static final MediaType FONT_TTF = createConstant(FONT_TYPE, "ttf");
+
+ /**
+ * Web Open Font Format (WOFF). RFC 8081 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");
+
+ /**
+ * Web Open Font Format (WOFF2).
+ * RFC 8081 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 parameters;
@@ -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.
*
diff --git a/guava-gwt/test/com/google/common/net/MediaTypeTest_gwt.java b/guava-gwt/test/com/google/common/net/MediaTypeTest_gwt.java
index 3e8a40efd39f..8af8d6415885 100644
--- a/guava-gwt/test/com/google/common/net/MediaTypeTest_gwt.java
+++ b/guava-gwt/test/com/google/common/net/MediaTypeTest_gwt.java
@@ -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();
diff --git a/guava-tests/test/com/google/common/net/MediaTypeTest.java b/guava-tests/test/com/google/common/net/MediaTypeTest.java
index 1276f97fe036..cec3cdd28cce 100644
--- a/guava-tests/test/com/google/common/net/MediaTypeTest.java
+++ b/guava-tests/test/com/google/common/net/MediaTypeTest.java
@@ -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());
diff --git a/guava/src/com/google/common/net/MediaType.java b/guava/src/com/google/common/net/MediaType.java
index 27babd858d23..2ba6c1e54e8c 100644
--- a/guava/src/com/google/common/net/MediaType.java
+++ b/guava/src/com/google/common/net/MediaType.java
@@ -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 = "*";
@@ -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");
@@ -189,6 +197,7 @@ private static MediaType addKnownType(MediaType mediaType) {
*/
public static final MediaType VTT_UTF_8 = createConstantUtf8(TEXT_TYPE, "vtt");
+ /* image types */
/**
* Bitmap file format ({@code bmp}
* files).
@@ -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 TrueType and OpenType fonts). This is registered with
- * the IANA.
+ * RFC 8081 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
*/
@@ -664,18 +672,18 @@ private static MediaType addKnownType(MediaType mediaType) {
public static final MediaType TAR = createConstant(APPLICATION_TYPE, "x-tar");
/**
- * Web Open Font Format (WOFF) defined by the W3C. This is registered with
- * the IANA.
+ * RFC 8081 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");
/**
- * Web Open Font Format (WOFF)
- * version 2 defined by the W3C.
+ * RFC 8081 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
*/
@@ -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 RFC
+ * 8081.
+ *
+ * @since NEXT
+ */
+ public static final MediaType FONT_COLLECTION = createConstant(FONT_TYPE, "collection");
+
+ /**
+ * Open Type Font Format (OTF) as defined by
+ * RFC 8081.
+ *
+ * @since NEXT
+ */
+ public static final MediaType FONT_OTF = createConstant(FONT_TYPE, "otf");
+
+ /**
+ * Spline or Scalable Font Format (SFNT). RFC 8081 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");
+
+ /**
+ * True Type Font Format (TTF) as defined by
+ * RFC 8081.
+ *
+ * @since NEXT
+ */
+ public static final MediaType FONT_TTF = createConstant(FONT_TYPE, "ttf");
+
+ /**
+ * Web Open Font Format (WOFF). RFC 8081 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");
+
+ /**
+ * Web Open Font Format (WOFF2).
+ * RFC 8081 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 parameters;
@@ -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.
*