Skip to content

improve support for Linux and macOS #211

Closed

Description

@hexxone

Hi there,

I was trying to get this Library working under a .net core 2.1 app on my ubuntu 18.04 server.
During this process I was getting some weird errors which were eventually boiled down to being the exact same issue like THIS

On this line: https://github.com/swharden/ScottPlot/blob/bbfa3f5d8264338814c946aaaee955f2c082313a/src/ScottPlot/Config/TextLabel.cs#L25

If I understood correctly, the usage of "FromHwnd" will basically invoke some code which requires a graphical interface to be present. As my server is purely a "backend" I dont really want to install an x-server just for plotting some graphs. This would be my last resort...

I am not familar with the Details, but as the solution on stackoverflow suggest, might there be a way to use Graphics.FromImage() at this place without any loss of funtionality?

I think this would greatly benefit cross-platform compatibility :)

Thanks in advance.

Activity

  1. StendProg commented on Jan 20, 2020

    @StendProg
    Contributor

    Hi @Hexxonite, you did good investigation. One more step is to make PR to fix that. You are best candidate, because you can easy reproduce your problem.
    Gfx object you point used only for MeasureString(). I think it safe to make replacement you suggested. It may have some side effects because FromHwnd may contain some DPI scaling information, not sure.
    If you get exception on Graphics.FromHwnd(IntPtr.Zero), safest way to fix as i see:

    private Graphics gfx = null;
    
    public TextLabel()
    {
    ...
    ...
        try 
        {
            gfx = Graphics.FromHwnd(IntPtr.Zero);
        }
        finally
        {
            if (gfx == null)
                gfx = Graphics.FromImage(new Bitmap(1, 1));
        }
    }

    Does Azure piplines use Windows instances to run tests? Its good improvement to setup additional Linux based pipeline for test, to avoid problems like this issue.

  2. hexxone commented on Jan 20, 2020

    @hexxone
    Author

    Hi again and Thanks for the quick response :)

    The method you proposed is working fine, however I encountered another error where the "Segoe UI"-Font wouldn't be found. So I created a Helper-Class to check if any preffered defaults exist on the system and replaced the static strings in some cases.

    During this I also encountered the "CourierNew" Font being used in some cases by "markers"? But I personally dont use these and didn't have any problems. Some further investigation might be required though...

    Regarding the Azure Pipeline I sadly dont have any knowledge but it seems like a good idea for sure :)

    Here is the PR:

    #212

  3. swharden commented on Jan 20, 2020

    @swharden
    Member

    Hi @Hexxonite, thanks for reporting this and issuing a PR. I'll refine the PR a bit then merge it in today.

    @StendProg thanks for your early reply. Azure Pipelines is just building on a Windows system, but I'll add Linux to it today and ensure ScottPlot builds and tests pass.

    The Azure Pipelines configuration file is: /dev/devops/azure-pipelines.yml

  4. changed the title [-]Library requires xserver on linux[/-] [+]improve support for Linux and macOS[/+] on Jan 20, 2020
  5. swharden commented on Jan 21, 2020

    @swharden
    Member

    fixed, see notes in #212

  6. added a commit that references this issue on Jan 28, 2020
  7. added a commit that references this issue on May 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions