Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-8215

TTeXDump does not support custom / modified line styles

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: 6.06/04
    • Fix Version/s: None
    • Component/s: Core Libraries, Graphics, Other
    • Labels:
      None
    • Environment:

      ROOT installed through MacPorts on Mac OSX El Capitan 10.11.4

      Description

      The TTeXDump output component does not support custom line styles (this includes modifications of the default line styles) because it contains hard-coded strings. The problem resides in the switch block in lines 525 – 555.

      Below I provide

      • a minimal example producing problematic output, as well as
      • a fix to TTexDump.

      The example fix can be used to convert from ROOT's line style string to a TikZ line-dash definition. I'm not really a TString user, so there may be a more efficient solution. I'd also suggest to cache the parsed result somehow since parsing the specification each time a line is drawn is very inefficient.

      I've verified the conversion function using the official line style definitions.


      Conversion routine from ROOT line style string to tikz code:

      #include <TString.h>
       
      float numToPt(int num){
          return 0.2 * num;
      }
       
      TString convertSpec(const TString & spec){
          TString tikzSpec;
       
          auto stripped = TString{spec.Strip(TString::kBoth)};
       
          if (not stripped.Length()){
              return tikzSpec;
          }
       
          tikzSpec.Append(",dash pattern=");
       
          Ssiz_t i{0}, j{0};
          bool on{true}, iterate{true};
       
          while (iterate){
              j = stripped.Index(" ", 1, i, TString::kExact);
       
              if (j == kNPOS){
                  iterate = false;
                  j = stripped.Length();
              }
       
              if (on){
                  tikzSpec.Append("on ");
                  on = false;
              } else {
                  tikzSpec.Append("off ");
                  on = true;
              }
       
              int num = TString{stripped(i, j - i)}.Atoi();
              float pt = numToPt(num);
       
              tikzSpec.Append(TString::Format("%.2fpt ", pt));
       
              i = j + 1;
          }
       
          return tikzSpec;
      }


      Minimal Example:

      import ROOT
      c = ROOT.TCanvas('c', '', 200, 200)
      ROOT.gStyle.SetLineStyleString(11, '4 4')
      l = ROOT.TLine()
      l.SetLineStyle(11)
      l.DrawLineNDC(0.1, 0.1, 0.9, 0.9)
       
      c.Print("foo.tex")
      c.Print("foo.pdf")

        Attachments

          Activity

            People

            • Assignee:
              couet Olivier Couet
              Reporter:
              fawilk Fabian Wilk (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Actual End: