Skip to content

Commit 571cf66

Browse files
sicternetdpb
authored andcommitted
Added support for the "font" Top-Level Media Type (https://tools.ietf.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
1 parent abea458 commit 571cf66

File tree

5 files changed

+183
-20
lines changed

5 files changed

+183
-20
lines changed

android/guava-tests/test/com/google/common/net/MediaTypeTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ public void testCreateAudioType() {
192192
assertEquals("yams", newType.subtype());
193193
}
194194

195+
public void testCreateFontType() {
196+
MediaType newType = MediaType.createFontType("yams");
197+
assertEquals("font", newType.type());
198+
assertEquals("yams", newType.subtype());
199+
}
200+
195201
public void testCreateImageType() {
196202
MediaType newType = MediaType.createImageType("yams");
197203
assertEquals("image", newType.type());

android/guava/src/com/google/common/net/MediaType.java

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public final class MediaType {
101101
private static final String IMAGE_TYPE = "image";
102102
private static final String TEXT_TYPE = "text";
103103
private static final String VIDEO_TYPE = "video";
104+
private static final String FONT_TYPE = "font";
104105

105106
private static final String WILDCARD = "*";
106107

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

145+
/**
146+
* Wildcard matching any "font" top-level media type.
147+
*
148+
* @since NEXT
149+
*/
150+
public static final MediaType ANY_FONT_TYPE = createConstant(FONT_TYPE, WILDCARD);
151+
144152
/* text types */
145153
public static final MediaType CACHE_MANIFEST_UTF_8 =
146154
createConstantUtf8(TEXT_TYPE, "cache-manifest");
@@ -189,6 +197,7 @@ private static MediaType addKnownType(MediaType mediaType) {
189197
*/
190198
public static final MediaType VTT_UTF_8 = createConstantUtf8(TEXT_TYPE, "vtt");
191199

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

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

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

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

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

706+
/* font types */
707+
708+
/**
709+
* A collection of font outlines as defined by <a href="https://tools.ietf.org/html/rfc8081">RFC
710+
* 8081</a>.
711+
*
712+
* @since NEXT
713+
*/
714+
public static final MediaType FONT_COLLECTION = createConstant(FONT_TYPE, "collection");
715+
716+
/**
717+
* <a href="https://en.wikipedia.org/wiki/OpenType">Open Type Font Format</a> (OTF) as defined by
718+
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a>.
719+
*
720+
* @since NEXT
721+
*/
722+
public static final MediaType FONT_OTF = createConstant(FONT_TYPE, "otf");
723+
724+
/**
725+
* <a href="https://en.wikipedia.org/wiki/SFNT">Spline or Scalable Font Format</a> (SFNT). <a
726+
* href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct media
727+
* type for SFNT, but {@link #SFNT application/font-sfnt} may be necessary in certain situations
728+
* for compatibility.
729+
*
730+
* @since NEXT
731+
*/
732+
public static final MediaType FONT_SFNT = createConstant(FONT_TYPE, "sfnt");
733+
734+
/**
735+
* <a href="https://en.wikipedia.org/wiki/TrueType">True Type Font Format</a> (TTF) as defined by
736+
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a>.
737+
*
738+
* @since NEXT
739+
*/
740+
public static final MediaType FONT_TTF = createConstant(FONT_TYPE, "ttf");
741+
742+
/**
743+
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF). <a
744+
* href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct media
745+
* type for SFNT, but {@link #WOFF application/font-woff} may be necessary in certain situations
746+
* for compatibility.
747+
*
748+
* @since NEXT
749+
*/
750+
public static final MediaType FONT_WOFF = createConstant(FONT_TYPE, "woff");
751+
752+
/**
753+
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF2).
754+
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct
755+
* media type for SFNT, but {@link #WOFF2 application/font-woff2} may be necessary in certain
756+
* situations for compatibility.
757+
*
758+
* @since NEXT
759+
*/
760+
public static final MediaType FONT_WOFF2 = createConstant(FONT_TYPE, "woff2");
761+
698762
private final String type;
699763
private final String subtype;
700764
private final ImmutableListMultimap<String, String> parameters;
@@ -931,6 +995,15 @@ static MediaType createAudioType(String subtype) {
931995
return create(AUDIO_TYPE, subtype);
932996
}
933997

998+
/**
999+
* Creates a media type with the "font" type and the given subtype.
1000+
*
1001+
* @throws IllegalArgumentException if subtype is invalid
1002+
*/
1003+
static MediaType createFontType(String subtype) {
1004+
return create(FONT_TYPE, subtype);
1005+
}
1006+
9341007
/**
9351008
* Creates a media type with the "image" type and the given subtype.
9361009
*

guava-gwt/test/com/google/common/net/MediaTypeTest_gwt.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public void testCreateAudioType() throws Exception {
2828
testCase.testCreateAudioType();
2929
}
3030

31+
public void testCreateFontType() throws Exception {
32+
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
33+
testCase.testCreateFontType();
34+
}
35+
3136
public void testCreateImageType() throws Exception {
3237
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
3338
testCase.testCreateImageType();

guava-tests/test/com/google/common/net/MediaTypeTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ public void testCreateAudioType() {
192192
assertEquals("yams", newType.subtype());
193193
}
194194

195+
public void testCreateFontType() {
196+
MediaType newType = MediaType.createFontType("yams");
197+
assertEquals("font", newType.type());
198+
assertEquals("yams", newType.subtype());
199+
}
200+
195201
public void testCreateImageType() {
196202
MediaType newType = MediaType.createImageType("yams");
197203
assertEquals("image", newType.type());

guava/src/com/google/common/net/MediaType.java

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public final class MediaType {
101101
private static final String IMAGE_TYPE = "image";
102102
private static final String TEXT_TYPE = "text";
103103
private static final String VIDEO_TYPE = "video";
104+
private static final String FONT_TYPE = "font";
104105

105106
private static final String WILDCARD = "*";
106107

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

145+
/**
146+
* Wildcard matching any "font" top-level media type.
147+
*
148+
* @since NEXT
149+
*/
150+
public static final MediaType ANY_FONT_TYPE = createConstant(FONT_TYPE, WILDCARD);
151+
144152
/* text types */
145153
public static final MediaType CACHE_MANIFEST_UTF_8 =
146154
createConstantUtf8(TEXT_TYPE, "cache-manifest");
@@ -189,6 +197,7 @@ private static MediaType addKnownType(MediaType mediaType) {
189197
*/
190198
public static final MediaType VTT_UTF_8 = createConstantUtf8(TEXT_TYPE, "vtt");
191199

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

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

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

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

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

706+
/* font types */
707+
708+
/**
709+
* A collection of font outlines as defined by <a href="https://tools.ietf.org/html/rfc8081">RFC
710+
* 8081</a>.
711+
*
712+
* @since NEXT
713+
*/
714+
public static final MediaType FONT_COLLECTION = createConstant(FONT_TYPE, "collection");
715+
716+
/**
717+
* <a href="https://en.wikipedia.org/wiki/OpenType">Open Type Font Format</a> (OTF) as defined by
718+
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a>.
719+
*
720+
* @since NEXT
721+
*/
722+
public static final MediaType FONT_OTF = createConstant(FONT_TYPE, "otf");
723+
724+
/**
725+
* <a href="https://en.wikipedia.org/wiki/SFNT">Spline or Scalable Font Format</a> (SFNT). <a
726+
* href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct media
727+
* type for SFNT, but {@link #SFNT application/font-sfnt} may be necessary in certain situations
728+
* for compatibility.
729+
*
730+
* @since NEXT
731+
*/
732+
public static final MediaType FONT_SFNT = createConstant(FONT_TYPE, "sfnt");
733+
734+
/**
735+
* <a href="https://en.wikipedia.org/wiki/TrueType">True Type Font Format</a> (TTF) as defined by
736+
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a>.
737+
*
738+
* @since NEXT
739+
*/
740+
public static final MediaType FONT_TTF = createConstant(FONT_TYPE, "ttf");
741+
742+
/**
743+
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF). <a
744+
* href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct media
745+
* type for SFNT, but {@link #WOFF application/font-woff} may be necessary in certain situations
746+
* for compatibility.
747+
*
748+
* @since NEXT
749+
*/
750+
public static final MediaType FONT_WOFF = createConstant(FONT_TYPE, "woff");
751+
752+
/**
753+
* <a href="http://en.wikipedia.org/wiki/Web_Open_Font_Format">Web Open Font Format</a> (WOFF2).
754+
* <a href="https://tools.ietf.org/html/rfc8081">RFC 8081</a> declares this to be the correct
755+
* media type for SFNT, but {@link #WOFF2 application/font-woff2} may be necessary in certain
756+
* situations for compatibility.
757+
*
758+
* @since NEXT
759+
*/
760+
public static final MediaType FONT_WOFF2 = createConstant(FONT_TYPE, "woff2");
761+
698762
private final String type;
699763
private final String subtype;
700764
private final ImmutableListMultimap<String, String> parameters;
@@ -931,6 +995,15 @@ static MediaType createAudioType(String subtype) {
931995
return create(AUDIO_TYPE, subtype);
932996
}
933997

998+
/**
999+
* Creates a media type with the "font" type and the given subtype.
1000+
*
1001+
* @throws IllegalArgumentException if subtype is invalid
1002+
*/
1003+
static MediaType createFontType(String subtype) {
1004+
return create(FONT_TYPE, subtype);
1005+
}
1006+
9341007
/**
9351008
* Creates a media type with the "image" type and the given subtype.
9361009
*

0 commit comments

Comments
 (0)