changcheng / wro4j

Automatically exported from code.google.com/p/wro4j
0 stars 0 forks source link

CssDataUriPreProcessor hits error (unknown mime type) for linked fonts #462

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Configure Wro4J to use CssDataUriPreProcessor
2. Have a CSS file with urls to fonts
3. Request that CSS file

What is the expected output? What do you see instead?
The CSS file with the font url

What version of the product are you using? On what operating system?
Wro4J 1.4.6; OSX 10.6.8

Please provide any additional information below.

Example troublesome CSS:

@font-face {
  font-family: 'ProximaNova';
  src: url("../../../fonts/Proxima_Nova_Bold-webfont.eot");
  /* IE9 Compat Modes */
  src: url("../../../fonts/Proxima_Nova_Bold-webfont.woff") format("embedded-opentype"), url("../../../fonts/Proxima_Nova_Bold-webfont.woff") format("woff"), url("../../../fonts/Proxima_Nova_Bold-webfont.ttf") format("truetype"), url("../../../fonts/Proxima_Nova_Bold-webfont.svg#webfont0R9JsQdw") format("svg");
  /* Legacy iOS */
  font-weight: bold;
  font-style: normal; }

Temporary fix (via extending CssDataUriPreProcessor):

@Override
    protected String replaceImageUrl(String cssUri, String imageUrl) {

    // this url hack works in our environment only
            if (!imageUrlToProcess.startsWith("../../fonts/")) {
                // See if we should inline the data for the resource
                // .eot (and other font extensions) have no recognizable mime type by the DataUriGenerator used by the
                // CssDataUriPreProcessor so lets not even attempt to inline the data.
                String dataUrl = super.replaceImageUrl(cssUri, imageUrl);
                if (!dataUrl.equals(imageUrl)) {
                    debug(LOG, "replace with data URI: %s ==> data:xxxxxx", imageUrl);
                    return dataUrl;
                }
            }

            return imageUrl;
      }

Original issue reported on code.google.com by aaron.si...@opower.com on 13 Jun 2012 at 4:37

GoogleCodeExporter commented 9 years ago
I still don't understand what is the expected behavior? Do you expect processor 
to not create dataUri for font url? 

Original comment by alex.obj...@gmail.com on 18 Jun 2012 at 8:42

GoogleCodeExporter commented 9 years ago
yes, it would just leave the source like it would for an image that is not 
inlined

Original comment by aaron.si...@opower.com on 18 Jun 2012 at 9:00

GoogleCodeExporter commented 9 years ago
Are you sure that dataUri's don't play well with fonts?

Original comment by alex.obj...@gmail.com on 19 Jun 2012 at 8:16

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 20 Jun 2012 at 4:16

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 20 Jun 2012 at 8:12