Exemplo n.º 1
0
 public override void WriteSVG(SvgWriter w)
 {
     w.SvgStartGroup(CSSObjectClass.ToString());
     w.SvgRect(CSSObjectClass.barNumberFrame, _left, _top, _right - _left, _bottom - _top);
     w.SvgText(CSSObjectClass.barNumberNumber, _number, _barNumberNumberMetrics.OriginX, _barNumberNumberMetrics.OriginY);
     w.SvgEndGroup();
 }
Exemplo n.º 2
0
        public virtual void WriteSVG(SvgWriter w, int systemNumber, int staffNumber, List <CarryMsgs> carryMsgsPerChannel, bool graphicsOnly)
        {
            w.WriteAttributeString("score", "staffName", null, this.Staffname);

            CSSObjectClass stafflinesClass = CSSObjectClass.stafflines;
            CSSObjectClass stafflineClass  = CSSObjectClass.staffline;

            w.SvgStartGroup(stafflinesClass.ToString());
            double stafflineY = this.Metrics.StafflinesTop;

            for (int staffLineIndex = 0; staffLineIndex < NumberOfStafflines; staffLineIndex++)
            {
                w.SvgLine(stafflineClass, this.Metrics.StafflinesLeft, stafflineY, this.Metrics.StafflinesRight, stafflineY);

                if (staffLineIndex < (NumberOfStafflines - 1))
                {
                    stafflineY += Gap;
                }
            }
            w.SvgEndGroup();

            for (var voiceIndex = 0; voiceIndex < Voices.Count; voiceIndex++)
            {
                Voices[voiceIndex].WriteSVG(w, voiceIndex, carryMsgsPerChannel, graphicsOnly);
            }

            foreach (var extender in Extenders)
            {
                extender.Metrics.WriteSVG(w);
            }
        }
Exemplo n.º 3
0
        public AccidentalMetrics(string accChar, double fontHeight, double gap, CSSObjectClass cssClass)
            : base(accChar, fontHeight, cssClass)
        {
            double verticalPadding = gap / 5;

            _top    -= verticalPadding;
            _bottom += verticalPadding;

            switch (_characterString)
            {
            case "b":
                _left  -= gap * 0.2;
                _right += gap * 0.2;
                break;

            case "n":
                _left  -= gap * 0.2;
                _right += gap * 0.2;
                break;

            case "#":
                _left  -= gap * 0.1;
                _right += gap * 0.1;
                break;
            }
        }
Exemplo n.º 4
0
 public BRMetrics(double leftReOriginX, double rightReOriginX,
                  CSSObjectClass lineClass1 = CSSObjectClass.normalBarline, CSSObjectClass lineClass2 = CSSObjectClass.normalBarline)
     : base(lineClass1, lineClass2)
 {
     _originX = 0;
     _left    = leftReOriginX;          // for a normal, thin barline: -(strokeWidth / 2);
     _right   = rightReOriginX;         // for a normal, thin barline: strokeWidth / 2;
 }
Exemplo n.º 5
0
 protected Metrics(CSSObjectClass cssObjectClass)
 {
     _cssObjectClass = cssObjectClass;
     if (!_usedCSSObjectClasses.Contains(cssObjectClass))
     {
         _usedCSSObjectClasses.Add(cssObjectClass);
     }
 }
Exemplo n.º 6
0
 public void SvgText(CSSObjectClass cssClass, string text, double x, double y)
 {
     _w.WriteStartElement("text");
     _w.WriteAttributeString("class", cssClass.ToString());
     _w.WriteAttributeString("x", M.DoubleToShortString(x));
     _w.WriteAttributeString("y", M.DoubleToShortString(y));
     _w.WriteString(text);
     _w.WriteEndElement(); // text
 }
Exemplo n.º 7
0
 public override void WriteSVG(SvgWriter w)
 {
     w.SvgStartGroup(CSSObjectClass.ToString());
     foreach (Metrics metrics in MetricsList)
     {
         metrics.WriteSVG(w);
     }
     w.SvgEndGroup();
 }
Exemplo n.º 8
0
 /// <summary>
 /// Writes an SVG "use" element, overriding its x- and y-coordinates.
 /// </summary>
 /// <param name="cssClass">Currently either CSSClass.clef or CSSClass.flag</param>
 /// <param name="cssClass">Currently either CSSClass.clef or CSSClass.flag</param>
 /// <param name="y">This element's y-coordinate.</param>
 /// <param name="idOfObjectToUse">(Do not include the leading '#'. It will be inserted automatically.)</param>
 public void SvgUseXY(CSSObjectClass cssClass, string idOfObjectToUse, double x, double y)
 {
     _w.WriteStartElement("use");
     _w.WriteAttributeString("class", cssClass.ToString());
     _w.WriteAttributeString("href", "#" + idOfObjectToUse);
     _w.WriteAttributeString("x", M.DoubleToShortString(x));
     _w.WriteAttributeString("y", M.DoubleToShortString(y));
     _w.WriteEndElement();
 }
Exemplo n.º 9
0
        /// <summary>
        /// Writes an SVG "circle" element having a class that has a CSS definiton elsewhere.
        /// </summary>
        /// <param name="type">Not written if null or empty</param>
        /// <param name="cx"></param>
        /// <param name="cy"></param>
        /// <param name="r"></param>
        public void SvgCircle(CSSObjectClass cssClass, double cx, double cy, double r)
        {
            WriteStartElement("circle");
            _w.WriteAttributeString("class", cssClass.ToString());
            WriteAttributeString("cx", M.DoubleToShortString(cx));
            WriteAttributeString("cy", M.DoubleToShortString(cy));
            WriteAttributeString("r", M.DoubleToShortString(r));

            WriteEndElement(); // circle
        }
Exemplo n.º 10
0
 /// <summary>
 /// Writes an SVG "rect" element having a class that has a CSS definiton elsewhere.
 /// </summary>
 /// <param name="type">must be a valid string</param>
 /// <param name="left"></param>
 /// <param name="top"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 public void SvgRect(CSSObjectClass cssClass, double left, double top, double width, double height)
 {
     _w.WriteStartElement("rect");
     _w.WriteAttributeString("class", cssClass.ToString());
     _w.WriteAttributeString("x", M.DoubleToShortString(left));
     _w.WriteAttributeString("y", M.DoubleToShortString(top));
     _w.WriteAttributeString("width", M.DoubleToShortString(width));
     _w.WriteAttributeString("height", M.DoubleToShortString(height));
     _w.WriteEndElement(); // rect
 }
Exemplo n.º 11
0
 protected Metrics(CSSObjectClass cssObjectClass1, CSSObjectClass cssObjectClass2)
 {
     if (!_usedCSSObjectClasses.Contains(cssObjectClass1))
     {
         _usedCSSObjectClasses.Add(cssObjectClass1);
     }
     if (!_usedCSSObjectClasses.Contains(cssObjectClass2))
     {
         _usedCSSObjectClasses.Add(cssObjectClass2);
     }
 }
Exemplo n.º 12
0
        public SmallClefMetrics(Clef clef, double gap, CSSObjectClass cssClass, ClefID clefID)
            : base(clef, gap, cssClass, clefID)
        {
            _right = 3.5F * gap;             // small clefs have proportionally more empty space on the right.

            if (clef.ClefType[0] == 'b' && clef.ClefType.Length > 1)
            {
                //double lowBassBottom = gap * 4.5;
                _bottom = gap * 4.65;                 // small bass clef octaves are lower than for normal bass clefs
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Used by Clone(cssClass)
 /// </summary>
 private TextMetrics(CSSObjectClass cssClass, double top, double right, double bottom, double left, double originX, double originY, TextInfo textInfo)
     : base(cssClass, textInfo.FontFamily, textInfo.FontHeight, textInfo.SVGFontWeight, textInfo.SVGFontStyle, textInfo.TextHorizAlign, textInfo.ColorString.String)
 {
     _top      = top;
     _right    = right;
     _bottom   = bottom;
     _left     = left;
     _originX  = originX;
     _originY  = originY;
     _textInfo = textInfo;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Writes an SVG "ellipse" element having a class that has a CSS definiton elsewhere.
        /// </summary>
        /// <param name="type">Not written if null or empty</param>
        /// <param name="cx"></param>
        /// <param name="cy"></param>
        /// <param name="rx"></param>
        /// <param name="ry"></param>
        public void SvgEllipse(CSSObjectClass cssClass, double cx, double cy, double rx, double ry)
        {
            WriteStartElement("ellipse");
            WriteAttributeString("class", cssClass.ToString());
            WriteAttributeString("cx", M.DoubleToShortString(cx));
            WriteAttributeString("cy", M.DoubleToShortString(cy));
            WriteAttributeString("rx", M.DoubleToShortString(rx));
            WriteAttributeString("ry", M.DoubleToShortString(ry));

            WriteEndElement(); // ellipse
        }
Exemplo n.º 15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="csslineClass"></param>
 /// <param name="strokeWidthPixels"></param>
 /// <param name="stroke">"none", "black", "white", "red" or a string of 6 hex characters</param>
 /// <param name="fill">"none", "black", "white", "red" or a string of 6 hex characters</param>
 /// <param name="lineCap"></param>
 public LineMetrics(CSSObjectClass csslineClass,
                    double strokeWidthPixels,
                    string stroke      = "none",
                    string fill        = "none",
                    CSSLineCap lineCap = CSSLineCap.butt)
     : base(csslineClass)
 {
     StrokeWidthPixels = strokeWidthPixels;
     Stroke            = stroke.ToString();
     Fill    = fill.ToString();
     LineCap = lineCap.ToString();
 }
Exemplo n.º 16
0
        public override void WriteSVG(SvgWriter w)
        {
            CSSObjectClass ledgerlineClass = CSSObjectClass.ledgerline;

            w.WriteStartElement("g");
            w.WriteAttributeString("class", CSSObjectClass.ToString());
            foreach (double y in Ys)
            {
                w.SvgLine(ledgerlineClass, _left + _strokeWidth, y, _right - _strokeWidth, y);
            }
            w.WriteEndElement();
        }
Exemplo n.º 17
0
        public LedgerlineBlockMetrics(double left, double right, double strokeWidth, CSSObjectClass ledgerlinesClass)
            : base(ledgerlinesClass, strokeWidth, "black")
        {
            /// The base class has deliberately been called with CSSClass.ledgerline (singular) here.
            /// This is so that its less confusing later when comparing the usage with stafflines/staffline.
            /// A ledgerline is always contained in a ledgerlines group.
            /// A staffline is always contained in a stafflines group.
            /// The CSS definition for ledgerlines is written if a ledgerline has been used.
            /// The CSS definition for stafflines is written if a staffline has been used.

            _left        = left;
            _right       = right;
            _strokeWidth = strokeWidth;
        }
Exemplo n.º 18
0
 /// <summary>
 /// Writes an SVG "line" element
 /// </summary>
 /// <param name="styleName">the line's CSS style name</param>
 /// <param name="x1"></param>
 /// <param name="y1"></param>
 /// <param name="x2"></param>
 /// <param name="y2"></param>
 /// <param name="strokeDashArray"></param>
 public void SvgLine(CSSObjectClass cssClass, double x1, double y1, double x2, double y2, string strokeDashArray = null)
 {
     _w.WriteStartElement("line");
     _w.WriteAttributeString("class", cssClass.ToString());
     _w.WriteAttributeString("x1", M.DoubleToShortString(x1));
     _w.WriteAttributeString("y1", M.DoubleToShortString(y1));
     _w.WriteAttributeString("x2", M.DoubleToShortString(x2));
     _w.WriteAttributeString("y2", M.DoubleToShortString(y2));
     if (strokeDashArray != null)
     {
         _w.WriteAttributeString("stroke-dasharray", strokeDashArray);
     }
     _w.WriteEndElement(); //line
 }
Exemplo n.º 19
0
        public override void WriteSVG(SvgWriter w)
        {
            w.SvgStartGroup(CSSObjectClass.ToString());

            w.SvgRect(CSSObjectClass.regionInfoFrame, _left, _top, _right - _left, _bottom - _top);

            for (int i = 0; i < _textMetrics.Count; ++i)
            {
                TextMetrics textMetrics = _textMetrics[i];
                string      textString  = _textStrings[i];
                w.SvgText(CSSObjectClass.regionInfoString, textString, textMetrics.OriginX, textMetrics.OriginY);
            }

            w.SvgEndGroup();
        }
Exemplo n.º 20
0
        public HeadMetrics(ChordSymbol chord, Head head, double gapVBPX, CSSObjectClass headClass)
            : base(chord.DurationClass, chord.FontHeight, headClass)
        {
            Move((Left - Right) / 2, 0F);             // centre horizontally

            double horizontalPadding = chord.FontHeight * 0.04;

            _leftStemX  = _left;
            _rightStemX = _right;
            _left      -= horizontalPadding;
            _right     += horizontalPadding;
            if (head != null)
            {
                CSSColorClass = head.ColorClass;
            }
        }
Exemplo n.º 21
0
        public TextStyle(CSSObjectClass cssTextClass, string fontFamily, double fontHeight, SVGFontWeight svgFontWeight, SVGFontStyle svgFontStyle,
                         TextHorizAlign textAnchor = TextHorizAlign.left, string fill = "black")
            : base(cssTextClass)
        {
            FontFamily = fontFamily;
            FontHeight = fontHeight;
            FontWeight = svgFontWeight;
            FontStyle  = svgFontStyle;

            switch (textAnchor)
            {
            case (TextHorizAlign.left):
                TextAnchor = "left";
                break;

            case (TextHorizAlign.center):
                TextAnchor = "middle";
                break;

            case (TextHorizAlign.right):
                TextAnchor = "right";
                break;
            }
            if (fill == "#FFFFFF" || fill == "FFFFFF")
            {
                Fill = "white";
            }
            else if (fill == "#000000" || fill == "000000")
            {
                Fill = "black";
            }
            else if (fill == "none" || fill == "white" || fill == "black" || fill == "red")
            {
                Fill = fill;
            }
            else
            {
                if (fill[0] != '#')
                {
                    fill.Insert(0, "#");
                }
                M.Assert(Regex.IsMatch(fill, @"^#[0-9a-fA-F]{6}$"));
                Fill = fill; // a string of the form "#AAAAAA"
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// An ExtenderMetrics is a textMetrics followed by (possibly dotted) horizontal line with a solid vertical end marker line on its right.
        /// </summary>
        /// <param name="left">The left coordinate of the displayed extender (with or without text)</param>
        /// <param name="right">The right coordinate of the displayed extender</param>
        /// <param name="hLineY">The y-coordinate of the horizontal line.</param>
        /// <param name="strokeDashArray">If null, the line will be solid.</param>
        /// <param name="endMarkerHeight">Is negative if extender is under its containing staff.</param>
        public ExtenderMetrics(CSSObjectClass cssObjectClass, TextMetrics textMetrics, double left, double right, double hLineY, string strokeDashArray, double endMarkerHeight,
                               bool displayEndMarker)
            : base(cssObjectClass)
        {
            _left    = left;
            _right   = right;
            _top     = hLineY; // the real height of the extender is ignored
            _bottom  = hLineY;
            _originX = _left;
            _originY = hLineY;

            _textMetrics      = textMetrics;
            _strokeDashArray  = strokeDashArray;
            _endMarkerHeight  = endMarkerHeight;
            _displayEndMarker = displayEndMarker;

            MetricsList.Add(textMetrics); // will be moved automatically
        }
Exemplo n.º 23
0
        internal SlurTieMetrics(CSSObjectClass slurOrTie, double gap, double originX, double originY, double rightX, bool slurTieOver)
            : base(slurOrTie)
        {
            _left    = originX; // never changes
            _right   = rightX;  // never changes
            _originX = originX; // never changes

            _originY = originY;
            if (slurTieOver)
            {
                _bottom = originY;
                _top    = originY - (gap * 12 / 32);
            }
            else
            {
                _top    = originY;
                _bottom = originY + (gap * 12 / 32);
            }
        }
Exemplo n.º 24
0
 /// <summary>
 /// Writes an SVG "path" element having no global css style (such as a slurTemplate or tieTemplate)
 /// </summary>
 public void SvgPath(CSSObjectClass cssClass, string dString, string stroke, string strokeWidth, string fill)
 {
     _w.WriteStartElement("path");
     _w.WriteAttributeString("class", cssClass.ToString());
     _w.WriteAttributeString("d", dString);
     if (string.IsNullOrEmpty(stroke) == false)
     {
         _w.WriteAttributeString("stroke", stroke);
     }
     if (string.IsNullOrEmpty(strokeWidth) == false)
     {
         _w.WriteAttributeString("stroke-width", strokeWidth);
     }
     if (string.IsNullOrEmpty(fill) == false)
     {
         _w.WriteAttributeString("fill", fill);
     }
     _w.WriteEndElement(); //path
 }
Exemplo n.º 25
0
        /// <summary>
        /// Used by AccidentalMetrics
        /// </summary>
        public CLichtCharacterMetrics(string characterString, double fontHeight, CSSObjectClass cssClass)
            : base(cssClass, "CLicht", fontHeight)
        {
            _characterString = characterString;
            //GetClichtCharacterString(head);

            M.Assert(_characterString != null);
            Metrics m = CLichtFontMetrics.CLichtGlyphBoundingBoxesDictPX[_characterString];

            _originY = 0;
            _top     = m.Top * fontHeight;
            _bottom  = m.Bottom * fontHeight;

            // move so that Left = 0.
            _left    = 0;
            _right   = (m.Right - m.Left) * fontHeight;
            _originX = -m.Left * fontHeight;

            _fontHeight = fontHeight;
        }
Exemplo n.º 26
0
        // Currently used only by HeadMetrics (to write coloured noteheads).
        public void SvgText(CSSObjectClass cssObjectClass, CSSColorClass cssColorClass, string text, double x, double y)
        {
            string classesString = cssObjectClass.ToString();

            if (cssColorClass != CSSColorClass.none && cssColorClass != CSSColorClass.black)
            {
                classesString = string.Concat(classesString, " ", cssColorClass.ToString());
            }
            ;

            _w.WriteStartElement("text");
            if (!String.IsNullOrEmpty(classesString))
            {
                _w.WriteAttributeString("class", classesString);
            }
            _w.WriteAttributeString("x", M.DoubleToShortString(x));
            _w.WriteAttributeString("y", M.DoubleToShortString(y));
            _w.WriteString(text);
            _w.WriteEndElement(); // text
        }
Exemplo n.º 27
0
        protected void SetCommonMetrics(Graphics graphics, List <DrawObject> drawObjects)
        {
            StaffMetrics staffMetrics = Voice.Staff.Metrics;

            foreach (DrawObject drawObject in DrawObjects)
            {
                if (drawObject is StaffNameText staffNameText)
                {
                    CSSObjectClass staffClass = CSSObjectClass.staffName;
                    StaffNameMetrics = new StaffNameMetrics(staffClass, graphics, staffNameText.TextInfo);
                    // move the staffname vertically to the middle of this staff
                    double staffheight = staffMetrics.StafflinesBottom - staffMetrics.StafflinesTop;
                    double dy          = (staffheight * 0.5F) + (Gap * 0.8F);
                    StaffNameMetrics.Move(0, dy);
                }
                if (drawObject is FramedBarNumberText framedBarNumberText)
                {
                    BarnumberMetrics = new BarnumberMetrics(graphics, framedBarNumberText.TextInfo, framedBarNumberText.FrameInfo);
                    // move the bar number to its default (=lowest) position above this staff.
                    BarnumberMetrics.Move(0, staffMetrics.StafflinesTop - BarnumberMetrics.Bottom - (Gap * 3));
                }
            }
        }
Exemplo n.º 28
0
        protected void WriteSVG(SvgWriter w, CSSObjectClass horizontalLineClass, CSSObjectClass verticalLineClass)
        {
            _textMetrics.WriteSVG(w);
            double textSpace = _textMetrics.Right - _textMetrics.Left;

            if (_textMetrics.TextInfo.Text.Length == 3)
            {
                textSpace *= 0.85;
            }
            else if (_textMetrics.TextInfo.Text.Length == 4)
            {
                textSpace *= 0.9;
            }
            var lineleft = _left + textSpace;

            w.SvgLine(horizontalLineClass, lineleft, _originY, _right, _originY, _strokeDashArray);

            if (_displayEndMarker)
            {
                // verticalLineClass must have style stroke-linecap:square
                w.SvgLine(verticalLineClass, _right, _originY, _right, _originY + _endMarkerHeight, null);
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// clichtDynamics: { "Ø", "∏", "π", "p", "P", "F", "f", "ƒ", "Ï", "Î" };
        ///                  pppp, ppp,  pp,  p,   mp,  mf,  f,   ff, fff, ffff
        /// </summary>
        /// <param name="gap"></param>
        /// <param name="textInfo"></param>
        /// <param name="isBelow"></param>
        /// <param name="topBoundary"></param>
        /// <param name="bottomBoundary"></param>
        public DynamicMetrics(double gap, TextInfo textInfo, bool isBelow, CSSObjectClass dynamicClass)
            : base(textInfo.Text, textInfo.FontHeight, TextHorizAlign.left, dynamicClass)
        {
            // visually centre the "italic" dynamic characters
            if (textInfo.Text == "p" || textInfo.Text == "f")            // p, f
            {
                Move(textInfo.FontHeight * 0.02, 0F);
            }
            else if (textInfo.Text == "F")            // mf
            {
                Move(textInfo.FontHeight * 0.1, 0F);
            }
            else
            {
                Move(textInfo.FontHeight * 0.05, 0F);
            }
            double dynamicWidth  = Right - Left;
            double moveLeftDelta = -(dynamicWidth / 2F) - (0.25F * gap);             // "centre" italics

            Move(moveLeftDelta, 0F);

            IsBelow = isBelow;
        }
Exemplo n.º 30
0
        /// <summary>
        /// A square bracket
        /// </summary>
        public void SvgCautionaryBracket(CSSObjectClass cssClass, bool isLeftBracket, double top, double right, double bottom, double left)
        {
            if (!isLeftBracket)
            {
                double temp = left;
                left  = right;
                right = temp;
            }
            string leftStr   = left.ToString("0.###", M.En_USNumberFormat);
            string topStr    = top.ToString("0.###", M.En_USNumberFormat);
            string rightStr  = right.ToString("0.###", M.En_USNumberFormat);
            string bottomStr = bottom.ToString("0.###", M.En_USNumberFormat);

            _w.WriteStartElement("path");
            _w.WriteAttributeString("class", cssClass.ToString());
            StringBuilder d = new StringBuilder();

            d.Append("M " + rightStr + "," + topStr + " ");
            d.Append("L " + leftStr + "," + topStr + " " +
                     leftStr + "," + bottomStr + " " +
                     rightStr + "," + bottomStr);
            _w.WriteAttributeString("d", d.ToString());
            _w.WriteEndElement(); // path
        }