Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the lookup case insensitive #9

Closed
CodeBendor opened this issue Sep 29, 2020 · 4 comments
Closed

Make the lookup case insensitive #9

CodeBendor opened this issue Sep 29, 2020 · 4 comments

Comments

@CodeBendor
Copy link

    private static FiggleFont FontFactory(string name)
    {
        using var stream = typeof(FiggleFonts).GetTypeInfo().Assembly.GetManifestResourceStream("Figgle.Fonts.zip");
        using var zip = new ZipArchive(stream, ZipArchiveMode.Read);
        var entry = zip.Entries.ToDictionary(x=> x.FullName, x => x)
            .FirstOrDefault(x => x.Key.ToLowerInvariant().Replace(" ", string.Empty) == (name+".flf").ToLowerInvariant().Replace(" ", string.Empty)).Value;


        if (entry == null)
            throw new FiggleException($"No embedded font exists with name \"{name}\".");

        using var entryStream = entry.Open();
            
        return FiggleFontParser.Parse(entryStream, _stringPool);
    }

    public static FiggleFont Parse(string name)
    {
        var x = FontFactory(name);
        return x;
    }
@drewnoakes
Copy link
Owner

This adds a public Parse method. I'm curious why you need that, given all fonts embedded within the assembly are already exposed as properties on this type.

@CodeBendor
Copy link
Author

CodeBendor commented Oct 5, 2020

The main point of the comment was to make the lookup within the zip file case insensitive (even space insensitive).

Parse was just a suggestion... I used it in my command line version of the code. All the predefined lookups in the FiggleFonts class felt unnecessarily cumbersome. If the fonts are in the zip file, return a result, if not punt.
public static FiggleFont SomeName => Lookup("somename");

Why? I wanted to use more fonts that I'd found and not have to predefined them. So I just wanted a quick way to look them up:

// simplified code
public static void Main(string[] args)      {
    string message = args[0];
    string font = args[1];
    try {
        var ff = FiggleFonts.Parse(font); // maybe there was another way to do this... 
        Console.WriteLine(ff.Render(message));
    } catch(Exception ex) {
        Console.WriteLine($"Exception: {ex.Message}");
        Console.WriteLine($"Couldn't find font {font}"); 
    }
}

@drewnoakes
Copy link
Owner

I used it in my command line version of the code

That makes sense.

I wanted to use more fonts that I'd found and not have to predefined them

I'd expect you to do that with FiggleFontParser directly. FiggleFonts is intended to make it easy to access the bundled fonts. Perhaps the readme can be extended with an example that shows this.

@drewnoakes
Copy link
Owner

An example of reading custom fonts was added to the README some time ago.

https://github.com/drewnoakes/figgle#loading-external-fonts

I'll close this out.

@drewnoakes drewnoakes closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants