Git Product home page Git Product logo

Comments (2)

stewienj avatar stewienj commented on August 15, 2024

I don't know if this will help you, but I've been using this JavaScript library in C++ by calling it via a .NET javascript compiler from Microsoft called ClearScript https://github.com/microsoft/ClearScript which works on Windows, Linux, and MacOS.

I use ClearScript in C# like this to run milsymbol.js:

V8ScriptEngine engine = new V8ScriptEngine(nameof(MilStd2525), V8ScriptEngineFlags.EnableDebugging);
string jsContents = string.Empty;
using (Stream stream = File.Open("milsymbol.js"))
{
  using (var reader = new StreamReader(stream))
  {
    jsContents = reader.ReadToEnd();
  }
}
engine.Execute(jsContents);

and I have a function that gives me the symbol like this:

public string CreateSymbolAsSvgString(int size, string sidc, out bool isValid)
{
  sidc = $"\"{sidc}\"";

  // Insert javascript as a string for the milsymbol creation
  var script = $@"var size = {size};
            var sidc = {sidc};
            var symbol = new ms.Symbol(sidc, {{ size: {size} }});
            var symbolValid = symbol.isValid(false);
            var symbolSvg = symbol.asSVG();";
  engine.Execute(script);

  isValid = (bool)engine.Script.symbolValid;

  // Return svg as string
  return (string)engine.Script.symbolSvg;
}

from milsymbol.

JackGit3 avatar JackGit3 commented on August 15, 2024

Thanks for the example code, I ended up doing something similar since I was using UE4, I just used the unreal.js plugin to handle the milsymbol side of things and then send the svg string over to cpp.

from milsymbol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.