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

use element applies referenced viewBox scaling. FontManager created. #414

Merged
merged 3 commits into from Feb 4, 2019
Merged

Conversation

peracto
Copy link
Contributor

@peracto peracto commented Feb 1, 2019

Before I begin, apologies, this is my first ever pull request ...

  1. The 'use' element.

When referencing a element that contains a viewBox attribute - the result should be scaled using the width/height defined on the use element and the width/height of the viewbox.

I created a test case ... "__issue-323-02-01" - but realise that I've not followed any proper naming convention.

  1. Fonts ... My use case required the use of adhoc fonts. The existing method SVGElement.PrivateFonts - partially solved the issue, but not completely ... Introducing the SvgFontManager.

When a font is requested in the render process, if the font is not found as an embedded SvgFont, it defers to the SvgFontManager.FindFont method. The SvgFontManager.FindFont searches a dictionary of fonts (pre loaded with the system fonts). If a font can't be found and a callback has been provided - then the callback should perform any validation and return a font (or null if not found/error). When the SvgFontManager can't identify the font, we then fallback to the SVGElement.PrivateFont method.

Example usage.

        SvgFontManager.FontLoaderCallback = name =>
        {
            var ff = Path.Combine(Config.FontsFolder, name + ".ttf");
            if (!File.Exists(ff))
            {
                Log.Error($"Font request ({name}) does not exist at {ff}");
                return null;
            }

            var rc = SvgFontManager.AddFontFile(ff);
            if (rc == null) Log.Error($"Font request ({name}) font not loaded. {ff}");
            return rc;
        };

@mrbean-bremen
Copy link
Member

this is my first ever pull request

Congratulations, and thanks :)

I created a test case ... "__issue-323-02-01" - but realise that I've not followed any proper naming convention.

I think it would be better to rename it to __pull_request-414-01 to relate it to the correct PR, but other than that, it looks good to me! I will have a closer look tomorrow, but so far it looks sensible.


namespace Svg
{
public static class SvgFontManager
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a description what this does and how it is used (along the lines you put in the comments in this PR already)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

complete.

@mrbean-bremen mrbean-bremen merged commit 32e7000 into svg-net:master Feb 4, 2019
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

Successfully merging this pull request may close these issues.

None yet

3 participants