Fonts support in CMS Theme.
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 13 Jan 2021 11:31:30 +0000 (12:31 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 13 Jan 2021 11:31:30 +0000 (12:31 +0100)
org.argeo.cms.ui/src/org/argeo/cms/ui/CmsTheme.java
org.argeo.cms.ui/src/org/argeo/cms/ui/util/BundleCmsTheme.java

index 4b3d186f7ae47cb3e2059befb3bd7376b781d595..e5089e35f65716ef02de5d15e4c73068f682f54c 100644 (file)
@@ -31,6 +31,9 @@ public interface CmsTheme {
        /** Relative paths to images such as icons. */
        Set<String> getImagesPaths();
 
+       /** Relative paths to fonts. */
+       Set<String> getFontsPaths();
+
        /** Tags to be added to the header section of the HTML page. */
        String getHtmlHeaders();
 
index 9b0d50e30ce54213a10e7a72fe233fa8f7cc7001..3b2669e02242e9f96c39238f5c4f804695933982 100644 (file)
@@ -40,6 +40,7 @@ public class BundleCmsTheme extends AbstractCmsTheme {
        private Set<String> rapCssPaths = new TreeSet<>();
        private Set<String> swtCssPaths = new TreeSet<>();
        private Set<String> imagesPaths = new TreeSet<>();
+       private Set<String> fontsPaths = new TreeSet<>();
 
        private String headerCss;
        private List<String> fonts = new ArrayList<>();
@@ -91,14 +92,15 @@ public class BundleCmsTheme extends AbstractCmsTheme {
                webCssPaths = addCss(themeBundle, "/css/");
                rapCssPaths = addCss(themeBundle, "/rap/");
                swtCssPaths = addCss(themeBundle, "/swt/");
-               addResources("*.png");
-               addResources("*.gif");
-               addResources("*.jpg");
-               addResources("*.jpeg");
-               addResources("*.svg");
-               addResources("*.ico");
-               addResources("*.woff");
-               addResources("*.woff2");
+               addImages("*.png");
+               addImages("*.gif");
+               addImages("*.jpg");
+               addImages("*.jpeg");
+               addImages("*.svg");
+               addImages("*.ico");
+
+               addFonts("*.woff");
+               addFonts("*.woff2");
 
                // fonts
                URL fontsUrl = themeBundle.getEntry(basePath + "fonts.txt");
@@ -180,7 +182,7 @@ public class BundleCmsTheme extends AbstractCmsTheme {
                }
        }
 
-       void addResources(String pattern) {
+       void addImages(String pattern) {
                Enumeration<URL> themeResources = themeBundle.findEntries(basePath, pattern, true);
                if (themeResources == null)
                        return;
@@ -199,6 +201,25 @@ public class BundleCmsTheme extends AbstractCmsTheme {
 
        }
 
+       void addFonts(String pattern) {
+               Enumeration<URL> themeResources = themeBundle.findEntries(basePath, pattern, true);
+               if (themeResources == null)
+                       return;
+               while (themeResources.hasMoreElements()) {
+                       String resource = themeResources.nextElement().getPath();
+                       // remove first '/' so that RWT registers it
+                       resource = resource.substring(1);
+                       if (!resource.endsWith("/")) {
+//                             if (resources.containsKey(resource))
+//                                     log.warn("Overriding " + resource + " from " + themeBundle.getSymbolicName());
+//                             resources.put(resource, themeBRL);
+                               fontsPaths.add(resource);
+                       }
+
+               }
+
+       }
+
        @Override
        public InputStream getResourceAsStream(String resourceName) throws IOException {
                URL res = themeBundle.getEntry(resourceName);
@@ -256,6 +277,11 @@ public class BundleCmsTheme extends AbstractCmsTheme {
                return imagesPaths;
        }
 
+       @Override
+       public Set<String> getFontsPaths() {
+               return fontsPaths;
+       }
+
        @Override
        public InputStream loadPath(String path) throws IOException {
                URL url = themeBundle.getResource(path);