Ejemplo n.º 1
0
    private static NoesisFont ImportFont(string filename, bool reimport, bool reload)
    {
        string     path = Path.ChangeExtension(filename, ".asset");
        NoesisFont font = AssetDatabase.LoadAssetAtPath <NoesisFont>(path);

        if (font == null)
        {
            Log("↔ Create " + filename);
            font = (NoesisFont)ScriptableObject.CreateInstance(typeof(NoesisFont));
            AssetDatabase.CreateAsset(font, path);
        }

        byte[] content = File.ReadAllBytes(filename);

        if (reimport || font.content == null || !font.content.SequenceEqual(content) || font.source != filename)
        {
            Log("→ ImportFont " + filename);
            font.source  = filename;
            font.content = content;
            EditorUtility.SetDirty(font);
            AssetDatabase.SaveAssets();
            Log("← ImportFont");
        }

        // Hot reloading of font
        if (NoesisUnity.Initialized && reimport && reload)
        {
            ReloadFont(font.source);
        }

        return(font);
    }
    private FrameworkElement GetRootIcon()
    {
        Noesis.Grid root = new Noesis.Grid();
        root.Background = new SolidColorBrush(Colors.White);

        Viewbox box = new Viewbox();

        box.Margin = new Thickness(10);

        if (_faces.Count > 0 && target != null)
        {
            NoesisFont font = (NoesisFont)target;

            TextBlock text = new TextBlock();
            text.Foreground  = new SolidColorBrush(Colors.Black);
            text.FontFamily  = new FontFamily(System.IO.Path.GetDirectoryName(font.source) + "/#" + _faces[0].family);
            text.FontWeight  = _faces[0].weight;
            text.FontStyle   = _faces[0].style;
            text.FontStretch = _faces[0].stretch;
            text.Text        = "Abg";

            box.Child = text;
        }

        root.Children.Add(box);
        return(root);
    }
    private static void FindFamilyNames(string directory, string family, HashSet <NoesisFont> fonts)
    {
        try
        {
            var files = Directory.GetFiles(directory)
                        .Where(s => s.EndsWith(".ttf", StringComparison.OrdinalIgnoreCase) ||
                               s.EndsWith(".otf", StringComparison.OrdinalIgnoreCase));

            foreach (var filename in files)
            {
                using (FileStream file = File.Open(filename, FileMode.Open))
                {
                    if (NoesisUnity.HasFamily(file, family))
                    {
                        string uri  = Path.ChangeExtension(NormalizePath(filename), ".asset");
                        string guid = AssetDatabase.AssetPathToGUID(uri);

                        if (!String.IsNullOrEmpty(guid))
                        {
                            NoesisFont f = AssetDatabase.LoadAssetAtPath <NoesisFont>(uri);

                            if (f != null)
                            {
                                fonts.Add(f);
                            }
                        }
                    }
                }
            }
        }
        catch (System.Exception) {}
    }
Ejemplo n.º 4
0
    public void Register(NoesisFont font)
    {
        bool register = false;

        string uri = font.source;
        Value  v;

        if (_fonts.TryGetValue(uri, out v))
        {
            register = v.font != font;

            v.refs++;
            v.font      = font;
            _fonts[uri] = v;
        }
        else
        {
            register    = true;
            _fonts[uri] = new Value()
            {
                refs = 1, font = font
            };
        }

        if (register)
        {
            string folder   = System.IO.Path.GetDirectoryName(uri);
            string filename = System.IO.Path.GetFileName(uri);
            RegisterFont(folder, filename);
        }
    }
    public void RegisterFont()
    {
        if (target != null)
        {
            NoesisFont font = (NoesisFont)target;
            if (font.source != null)
            {
                NoesisUnity.Init();

                using (MemoryStream stream = new MemoryStream(font.content))
                {
                    _index = 0;
                    _faces.Clear();
                    Noesis.GUI.EnumFontFaces(stream, (index_, family_, weight_, style_, stretch_) =>
                    {
                        _faces.Add(new Face()
                        {
                            index = index_, family = family_, weight = weight_, style = style_, stretch = stretch_
                        });
                    });
                }

                if (_faces.Count > 0)
                {
                    NoesisFontProvider.instance.Register(font);
                }
            }
        }
    }
    private FrameworkElement GetRoot()
    {
        StackPanel root = new StackPanel();

        root.Background = new SolidColorBrush(Colors.White);

        if (_faces.Count > 0 && target != null)
        {
            _index = System.Math.Min(_index, _faces.Count - 1);
            NoesisFont font   = (NoesisFont)target;
            FontFamily family = new FontFamily(System.IO.Path.GetDirectoryName(font.source) + "/#" + _faces[_index].family);

            TextBlock text = new TextBlock();
            text.Margin     = new Thickness(2);
            text.Foreground = new SolidColorBrush(Colors.Black);

            AddRun(text, 12, family);
            AddRun(text, 18, family);
            AddRun(text, 24, family);
            AddRun(text, 36, family);
            AddRun(text, 48, family);
            AddRun(text, 60, family);
            AddRun(text, 72, family);

            root.Children.Add(text);
        }

        return(root);
    }
Ejemplo n.º 7
0
 public void RegisterFont()
 {
     if (target != null)
     {
         NoesisFont font = (NoesisFont)target;
         if (font.source != null)
         {
             NoesisUnity.Init();
             RegisterFont(font);
         }
     }
 }
    public void UnregisterFont()
    {
        if (target != null && _faces.Count > 0)
        {
            NoesisFont font = (NoesisFont)target;
            if (font.source != null)
            {
                NoesisFontProvider.instance.Unregister(font);
            }
        }

        _faces.Clear();
    }
Ejemplo n.º 9
0
    public void Unregister(NoesisFont font)
    {
        string uri = font.source;
        Value  v;

        if (_fonts.TryGetValue(uri, out v))
        {
            if (v.refs == 1)
            {
                _fonts.Remove(uri);
            }
            else
            {
                v.refs--;
                _fonts[uri] = v;
            }
        }
    }
Ejemplo n.º 10
0
    private void RegisterFont(NoesisFont font)
    {
        using (MemoryStream stream = new MemoryStream(font.content))
        {
            _index = 0;
            _faces.Clear();
            Noesis.GUI.EnumFontFaces(stream, (index_, family_, weight_, style_, stretch_) =>
            {
                _faces.Add(new Face()
                {
                    index = index_, family = family_, weight = weight_, style = style_, stretch = stretch_
                });
            });
        }

        if (_faces.Count > 0)
        {
            NoesisFontProvider.instance.Register(font);
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Imports a TrueType into a NoesisFont asset
    /// </summary>
    private static void ImportFont(string filename)
    {
        using (FileStream file = File.Open(filename, FileMode.Open))
        {
            string     path = Path.ChangeExtension(filename, ".asset");
            NoesisFont font = AssetDatabase.LoadAssetAtPath <NoesisFont>(path);

            if (font == null)
            {
                font         = (NoesisFont)ScriptableObject.CreateInstance(typeof(NoesisFont));
                font.source  = filename;
                font.content = new byte[file.Length];
                file.Read(font.content, 0, (int)file.Length);
                AssetDatabase.CreateAsset(font, path);
            }
            else
            {
                font.content = new byte[file.Length];
                file.Read(font.content, 0, (int)file.Length);
                EditorUtility.SetDirty(font);
            }
        }
    }
Ejemplo n.º 12
0
 private void UnregisterFont(NoesisFont font)
 {
     NoesisFontProvider.instance.Unregister(font);
 }