// Path: src/main/java/in/drifted/planisphere/l10n/LocalizationUtil.java
// public final class LocalizationUtil {
// 
//     private static final String LOCALE_BUNDLE = "in.drifted.planisphere.resources.localizations.messages";
//     private static final Control UNICODE_CONTROL = new UnicodeControl();
//     private ResourceBundle resources;
//     private ResourceBundle resourcesFallback;
// 
//     public LocalizationUtil(Locale locale) {
// 
//         try {
//             resources = ResourceBundle.getBundle(LOCALE_BUNDLE, locale, UNICODE_CONTROL);
//             resourcesFallback = ResourceBundle.getBundle(LOCALE_BUNDLE, Locale.ENGLISH, UNICODE_CONTROL);
// 
//         } catch (MissingResourceException e) {
//             resources = ResourceBundle.getBundle(LOCALE_BUNDLE, Locale.ENGLISH, UNICODE_CONTROL);
//             resourcesFallback = resources;
//         }
//     }
// 
//     public Collection<String> getKeyCollection() {
//         return resources.keySet();
//     }
// 
//     public String getValue(String key) {
//         switch (key) {
//             case "year":
//                 return String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
//             default:
//                 if (resources.containsKey(key)) {
//                     return resources.getString(key);
//                 } else if (resourcesFallback.containsKey(key)) {
//                     return resourcesFallback.getString(key);
//                 } else {
//                     return key;
//                 }
//         }
//     }
// 
//     public String getValue(String key, Double latitude) {
//         switch (key) {
//             case "latitudeValue":
//                 String strNorth = getValue("cardinalPointNorth");
//                 String strSouth = getValue("cardinalPointSouth");
//                 return Math.abs(latitude.intValue()) + " " + ((latitude < 0) ? strSouth : strNorth);
//             default:
//                 return getValue(key);
//         }
//     }
// 
//     public String translate(String content, Double latitude) {
//         String[] chunksRaw = content.split("\\$\\{");
//         if (chunksRaw.length <= 1) {
//             return content;
//         }
//         List<String> chunkList = new LinkedList<>();
//         for (String chunk : chunksRaw) {
//             if (!chunk.contains("}")) {
//                 if (chunk.length() > 0) {
//                     chunkList.add(chunk);
//                 }
//             } else {
//                 int index = chunk.indexOf("}");
//                 String key = chunk.substring(0, index);
//                 chunkList.add(getValue(key, latitude));
//                 if (index != chunk.length() - 1) {
//                     chunkList.add(chunk.substring(index + 1));
//                 }
//             }
//         }
// 
//         StringBuilder contentUpdated = new StringBuilder();
//         for (String chunk : chunkList) {
//             contentUpdated.append(chunk);
//         }
// 
//         return contentUpdated.toString();
//     }
// }


import in.drifted.planisphere.l10n.LocalizationUtil;
import java.text.DateFormatSymbols;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;

/* 
 * Copyright (c) 2012-present Jan Tošovský <jan.tosovsky.cz@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package in.drifted.planisphere.util;


public class SubsetUtil {

    public static String getFontForgeSelectionScript(Locale locale) {

        /*

         Method Used for subsetting this huge font for non-latin languages:
         https://github.com/android/platform_frameworks_base/blob/master/data/fonts/DroidSansFallback.ttf

         1. Generate script and copy it from e.g. debug window into the clipboard
         2. Open FontForge | File | Open... and choose DroidSansFallback.ttf
         3. Choose File | Execute script...
         4. Insert the script to the dialog area and press Ok
         5. Choose Edit | Selection | Invert Selection
         6. Choose Encoding | Detach & Remove glyphs... (removing glyphs takes quite long)
         7. Choose Element | Font Info... | OS/2 | Misc. | Embeddable and select 'Installable Font'
         8. Choose File | Generate Fonts...
         9. Store the final file in the following path: \in\drifted\planisphere\core\src\main\resources\in\drifted\planisphere\resources\fonts\droid-sans-[locale].ttf

         */
        StringBuilder sb = new StringBuilder("Select(32, 127)\n");

        for (Integer codePoint : getCodePointCollection(locale)) {
            sb.append("SelectMoreSingletons(");
            sb.append(codePoint);
            sb.append(")\n");
        }

        return sb.toString();
    }

    private static Collection<Integer> getCodePointCollection(Locale locale) {

        Collection<Integer> codePointCollection = new HashSet<>();


// Path: src/main/java/in/drifted/planisphere/l10n/LocalizationUtil.java
// public final class LocalizationUtil {
// 
//     private static final String LOCALE_BUNDLE = "in.drifted.planisphere.resources.localizations.messages";
//     private static final Control UNICODE_CONTROL = new UnicodeControl();
//     private ResourceBundle resources;
//     private ResourceBundle resourcesFallback;
// 
//     public LocalizationUtil(Locale locale) {
// 
//         try {
//             resources = ResourceBundle.getBundle(LOCALE_BUNDLE, locale, UNICODE_CONTROL);
//             resourcesFallback = ResourceBundle.getBundle(LOCALE_BUNDLE, Locale.ENGLISH, UNICODE_CONTROL);
// 
//         } catch (MissingResourceException e) {
//             resources = ResourceBundle.getBundle(LOCALE_BUNDLE, Locale.ENGLISH, UNICODE_CONTROL);
//             resourcesFallback = resources;
//         }
//     }
// 
//     public Collection<String> getKeyCollection() {
//         return resources.keySet();
//     }
// 
//     public String getValue(String key) {
//         switch (key) {
//             case "year":
//                 return String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
//             default:
//                 if (resources.containsKey(key)) {
//                     return resources.getString(key);
//                 } else if (resourcesFallback.containsKey(key)) {
//                     return resourcesFallback.getString(key);
//                 } else {
//                     return key;
//                 }
//         }
//     }
// 
//     public String getValue(String key, Double latitude) {
//         switch (key) {
//             case "latitudeValue":
//                 String strNorth = getValue("cardinalPointNorth");
//                 String strSouth = getValue("cardinalPointSouth");
//                 return Math.abs(latitude.intValue()) + " " + ((latitude < 0) ? strSouth : strNorth);
//             default:
//                 return getValue(key);
//         }
//     }
// 
//     public String translate(String content, Double latitude) {
//         String[] chunksRaw = content.split("\\$\\{");
//         if (chunksRaw.length <= 1) {
//             return content;
//         }
//         List<String> chunkList = new LinkedList<>();
//         for (String chunk : chunksRaw) {
//             if (!chunk.contains("}")) {
//                 if (chunk.length() > 0) {
//                     chunkList.add(chunk);
//                 }
//             } else {
//                 int index = chunk.indexOf("}");
//                 String key = chunk.substring(0, index);
//                 chunkList.add(getValue(key, latitude));
//                 if (index != chunk.length() - 1) {
//                     chunkList.add(chunk.substring(index + 1));
//                 }
//             }
//         }
// 
//         StringBuilder contentUpdated = new StringBuilder();
//         for (String chunk : chunkList) {
//             contentUpdated.append(chunk);
//         }
// 
//         return contentUpdated.toString();
//     }
// }


// Path: src/main/java/in/drifted/planisphere/util/SubsetUtil.java
import in.drifted.planisphere.l10n.LocalizationUtil;
import java.text.DateFormatSymbols;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;

/* 
 * Copyright (c) 2012-present Jan Tošovský <jan.tosovsky.cz@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package in.drifted.planisphere.util;


public class SubsetUtil {

    public static String getFontForgeSelectionScript(Locale locale) {

        /*

         Method Used for subsetting this huge font for non-latin languages:
         https://github.com/android/platform_frameworks_base/blob/master/data/fonts/DroidSansFallback.ttf

         1. Generate script and copy it from e.g. debug window into the clipboard
         2. Open FontForge | File | Open... and choose DroidSansFallback.ttf
         3. Choose File | Execute script...
         4. Insert the script to the dialog area and press Ok
         5. Choose Edit | Selection | Invert Selection
         6. Choose Encoding | Detach & Remove glyphs... (removing glyphs takes quite long)
         7. Choose Element | Font Info... | OS/2 | Misc. | Embeddable and select 'Installable Font'
         8. Choose File | Generate Fonts...
         9. Store the final file in the following path: \in\drifted\planisphere\core\src\main\resources\in\drifted\planisphere\resources\fonts\droid-sans-[locale].ttf

         */
        StringBuilder sb = new StringBuilder("Select(32, 127)\n");

        for (Integer codePoint : getCodePointCollection(locale)) {
            sb.append("SelectMoreSingletons(");
            sb.append(codePoint);
            sb.append(")\n");
        }

        return sb.toString();
    }

    private static Collection<Integer> getCodePointCollection(Locale locale) {

        Collection<Integer> codePointCollection = new HashSet<>();


        LocalizationUtil localizationUtil = new LocalizationUtil(locale);
