Exemplo n.º 1
0
        private float GetLeftMarginPos(SvgSystem system, Graphics graphics, PageFormat pageFormat)
        {
            float leftMarginPos = pageFormat.LeftMarginPos;
            float maxNameWidth  = 0;

            foreach (Staff staff in system.Staves)
            {
                foreach (NoteObject noteObject in staff.Voices[0].NoteObjects)
                {
                    Barline firstBarline = noteObject as Barline;
                    if (firstBarline != null)
                    {
                        foreach (DrawObject drawObject in firstBarline.DrawObjects)
                        {
                            StaffNameText staffName = drawObject as StaffNameText;
                            if (staffName != null)
                            {
                                Debug.Assert(staffName.TextInfo != null);

                                TextMetrics staffNameMetrics = new TextMetrics(graphics, null, staffName.TextInfo);
                                float       nameWidth        = staffNameMetrics.Right - staffNameMetrics.Left;
                                maxNameWidth = (maxNameWidth > nameWidth) ? maxNameWidth : nameWidth;
                            }
                        }
                        break;
                    }
                }
            }
            leftMarginPos = maxNameWidth + (pageFormat.Gap * 2.0F);
            leftMarginPos = (leftMarginPos > pageFormat.LeftMarginPos) ? leftMarginPos : pageFormat.LeftMarginPos;

            return(leftMarginPos);
        }
Exemplo n.º 2
0
        public TimeSignatureMetrics(Graphics graphics, double gap, int numberOfStafflines, TextInfo numeratorTextInfo, TextInfo denominatorTextInfo)
            : base(CSSObjectClass.timeSig)
        {
            string suffix = "_" + numeratorTextInfo.Text + "/" + denominatorTextInfo.Text;

            _timeSigID = CSSObjectClass.timeSig.ToString() + suffix;

            if (!TimeSigDefs.ContainsKey(_timeSigID))
            {
                List <TextMetrics> textMetricss = new List <TextMetrics>
                {
                    new TextMetrics(CSSObjectClass.timeSigNumerator, graphics, numeratorTextInfo),
                    new TextMetrics(CSSObjectClass.timeSigDenominator, graphics, denominatorTextInfo)
                };

                var numerMetrics = textMetricss[0];
                var denomMetrics = textMetricss[1];

                SetThisMetrics(numerMetrics, denomMetrics, gap);

                TimeSigDefs.Add(_timeSigID, textMetricss);
            }

            var         textMetricsList = TimeSigDefs[_timeSigID];
            TextMetrics numerTM         = TimeSigDefs[_timeSigID][0];
            TextMetrics denomTM         = TimeSigDefs[_timeSigID][1];
            TextMetrics numerCloneTM    = numerTM.Clone(CSSObjectClass.timeSigNumerator);
            TextMetrics denomCloneTM    = denomTM.Clone(CSSObjectClass.timeSigDenominator);

            _textMetricsList.Add(numerCloneTM);
            _textMetricsList.Add(denomCloneTM);

            SetThisMetrics(numerCloneTM, denomCloneTM, gap);
        }
Exemplo n.º 3
0
        private void SetThisMetrics(TextMetrics numerMetrics, TextMetrics denomMetrics, double gap)
        {
            numerMetrics.Move(0, 0 - numerMetrics.Bottom);
            denomMetrics.Move(0, (gap * 0.05) - denomMetrics.Top);

            _originY = gap * 2; // middle line of staff
            _top     = numerMetrics.Top;
            _bottom  = denomMetrics.Bottom;

            double nWidth = numerMetrics.Right - numerMetrics.Left;
            double dWidth = denomMetrics.Right - denomMetrics.Left;
            double width  = (nWidth > dWidth) ? nWidth : dWidth;

            _originX = 0; // left aligned
            if (nWidth < width)
            {
                numerMetrics.Move((width - nWidth) / 2, 0);
            }
            if (dWidth < width)
            {
                denomMetrics.Move((width - dWidth) / 2, 0);
            }
            _right = (numerMetrics.Right > denomMetrics.Right) ? numerMetrics.Right : denomMetrics.Right;
            _left  = (numerMetrics.Left < denomMetrics.Left) ? numerMetrics.Left : denomMetrics.Left;
        }
Exemplo n.º 4
0
 public BarnumberMetrics(Graphics graphics, TextInfo textInfo, FramePadding framePadding)
     : base(CSSObjectClass.barNumber)
 {
     _barNumberNumberMetrics = new TextMetrics(CSSObjectClass.barNumberNumber, graphics, textInfo);
     _number = textInfo.Text;
     _top    = _barNumberNumberMetrics.Top - framePadding.Top;
     _right  = _barNumberNumberMetrics.Right + framePadding.Right;
     _bottom = _barNumberNumberMetrics.Bottom + framePadding.Bottom;
     _left   = _barNumberNumberMetrics.Left - framePadding.Left;
 }
Exemplo n.º 5
0
        public BarnumberMetrics(Graphics graphics, string ID_Type, TextInfo textInfo, FrameInfo frameInfo)
            : base(graphics, ID_Type, textInfo)
        {
            TextMetrics textMetrics = new TextMetrics(graphics, null, textInfo);

            _top         = textMetrics.Top - frameInfo.PaddingY;
            _right       = textMetrics.Right + frameInfo.PaddingX;
            _bottom      = textMetrics.Bottom + frameInfo.PaddingY;
            _left        = textMetrics.Left - frameInfo.PaddingX;
            _strokeWidth = frameInfo.StrokeWidth;
        }
Exemplo n.º 6
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.º 7
0
        public BarlineMetrics(Graphics graphics, Barline barline, float gap)
            : base()
        {
            _objectType = "barline";
            if (barline.BarlineType == BarlineType.end)
            {
                _left = -gap * 1.7F;
            }
            else
            {
                _left = -gap * 0.5F;
            }
            _originX = 0F;
            _right   = gap / 2F;

            if (graphics != null && barline != null)
            {
                foreach (DrawObject drawObject in barline.DrawObjects)
                {
                    Text text = drawObject as Text;
                    if (text != null)
                    {
                        Debug.Assert(text.TextInfo != null &&
                                     (text is StaffNameText || text is FramedBarNumberText));

                        if (text is StaffNameText)
                        {
                            _staffNameMetrics = new TextMetrics(graphics, null, text.TextInfo);
                            // move the staffname vertically to the middle of this staff
                            Staff staff       = barline.Voice.Staff;
                            float staffheight = staff.Gap * (staff.NumberOfStafflines - 1);
                            float dy          = (staffheight * 0.5F) + (gap * 0.8F);
                            _staffNameMetrics.Move(0F, dy);
                        }
                        else if (text is FramedBarNumberText)
                        {
                            _barnumberMetrics = new BarnumberMetrics(graphics, null, text.TextInfo, text.FrameInfo);
                            //_barnumberMetrics = new TextMetrics(graphics, null, text.TextInfo);
                            // move the bar number above this barline
                            float deltaY = (gap * 6F);
                            _barnumberMetrics.Move(0F, -deltaY);
                        }
                    }
                }
            }
        }
Exemplo n.º 8
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.º 9
0
        // TupletMetrics(textMetrics, bracketHoriz, bracketLeft, bracketRight, bracketHeight, isOver)
        public TupletMetrics(TextMetrics textMetrics, double bracketHoriz, double bracketLeft, double bracketRight, double bracketHeight, bool isOver)
            : base(CSSObjectClass.tupletBracket)
        {
            _tupletTextMetrics = textMetrics;
            _text = textMetrics.TextInfo.Text;

            double bracketTop    = (isOver) ? bracketHoriz: bracketHoriz - bracketHeight;
            double bracketBottom = (isOver) ? bracketHoriz + bracketHeight : bracketHoriz;

            _top    = (textMetrics.Top < bracketTop) ? textMetrics.Top : bracketTop;
            _right  = (textMetrics.Right > bracketRight) ? textMetrics.Right : bracketRight;
            _bottom = (textMetrics.Bottom > bracketBottom) ? textMetrics.Bottom : bracketBottom;
            _left   = (textMetrics.Left < bracketLeft) ? textMetrics.Left : bracketLeft;

            _bracketBoundary = new TupletBracketBoundaryMetrics(bracketTop, bracketRight, bracketBottom, bracketLeft, isOver);

            MetricsList.Add(textMetrics);
            MetricsList.Add(_bracketBoundary);
        }
Exemplo n.º 10
0
        public OctaveShiftExtender(OctaveShift octaveShift, Graphics graphics, double leftChordLeft, double rightChordRight, double chordsY, double gap,
                                   bool isContinuation, bool displayEndMarker)
        {
            string text = null;

            switch (octaveShift.Type)
            {
            case OctaveShiftType.down3Oct:
                text = "3oct";
                break;

            case OctaveShiftType.down2Oct:
                text = "2oct";
                break;

            case OctaveShiftType.down1Oct:
                text = "8va";
                break;

            case OctaveShiftType.up1Oct:
                text = "8va";     // bassa
                break;

            case OctaveShiftType.up2Oct:
                text = "2oct";     // bassa
                break;

            case OctaveShiftType.up3Oct:
                text = "3oct";     // bassa
                break;
            }

            double hLineY          = 0;
            double textY           = 0;
            double textFontHeight  = M.PageFormat.OctaveShiftExtenderTextFontHeight;
            double endMarkerHeight = gap * 0.8;

            if (octaveShift.Orient == MNX.Common.Orientation.up)
            {
                hLineY = chordsY - (gap * 1.3);
                textY  = hLineY + (textFontHeight * 0.6);
            }
            else
            {
                hLineY           = chordsY + (gap * 1.2);
                textY            = hLineY + (gap * 0.1);
                endMarkerHeight *= -1;
            }

            string dashArrayString = (gap / 2).ToString(); // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray

            TextInfo textInfo = null;

            if (isContinuation)
            {
                text     = "(" + text + ")";
                textInfo = new TextInfo(text, M.PageFormat.OctaveShiftExtenderTextFontFamily, textFontHeight * 0.9, SVGFontWeight.normal, SVGFontStyle.italic, TextHorizAlign.left);
            }
            else
            {
                textInfo = new TextInfo(text, M.PageFormat.OctaveShiftExtenderTextFontFamily, textFontHeight, SVGFontWeight.bold, SVGFontStyle.italic, TextHorizAlign.left);
            }
            TextMetrics textMetrics = new TextMetrics(CSSObjectClass.octaveShiftExtenderText, graphics, textInfo);

            textMetrics.Move(leftChordLeft - textMetrics.Left, textY - textMetrics.OriginY);

            Metrics = new OctaveShiftExtenderMetrics(textMetrics, leftChordLeft, rightChordRight, hLineY, dashArrayString, endMarkerHeight, displayEndMarker);
        }
Exemplo n.º 11
0
        private float GetLeftMarginPos(SvgSystem system, Graphics graphics, PageFormat pageFormat)
        {
            float leftMarginPos = pageFormat.LeftMarginPos;
            float maxNameWidth = 0;
            foreach(Staff staff in system.Staves)
            {
                foreach(NoteObject noteObject in staff.Voices[0].NoteObjects)
                {
                    Barline firstBarline = noteObject as Barline;
                    if(firstBarline != null)
                    {
                        foreach(DrawObject drawObject in firstBarline.DrawObjects)
                        {
                            StaffNameText staffName = drawObject as StaffNameText;
                            if(staffName != null)
                            {
                                Debug.Assert(staffName.TextInfo != null);

                                TextMetrics staffNameMetrics = new TextMetrics(graphics, null, staffName.TextInfo);
                                float nameWidth = staffNameMetrics.Right - staffNameMetrics.Left;
                                maxNameWidth = (maxNameWidth > nameWidth) ? maxNameWidth : nameWidth;
                            }
                        }
                        break;
                    }
                }
            }
            leftMarginPos = maxNameWidth + (pageFormat.Gap * 2.0F);
            leftMarginPos = (leftMarginPos > pageFormat.LeftMarginPos) ? leftMarginPos : pageFormat.LeftMarginPos;

            return leftMarginPos;
        }
Exemplo n.º 12
0
 public BarnumberMetrics(Graphics graphics, string ID_Type, TextInfo textInfo, FrameInfo frameInfo)
     : base(graphics, ID_Type, textInfo)
 {
     TextMetrics textMetrics = new TextMetrics(graphics, null, textInfo);
     _top = textMetrics.Top - frameInfo.PaddingY;
     _right = textMetrics.Right + frameInfo.PaddingX;
     _bottom = textMetrics.Bottom + frameInfo.PaddingY;
     _left = textMetrics.Left - frameInfo.PaddingX;
     _strokeWidth = frameInfo.StrokeWidth;
 }
Exemplo n.º 13
0
        public BarlineMetrics(Graphics graphics, Barline barline, float gap)
            : base()
        {
            _objectType = "barline";
            if(barline.BarlineType == BarlineType.end)
                _left = -gap * 1.7F;
            else
                _left = -gap * 0.5F;
            _originX = 0F;
            _right = gap / 2F;

            if(graphics != null && barline != null)
            {
                foreach(DrawObject drawObject in barline.DrawObjects)
                {
                    Text text = drawObject as Text;
                    if(text != null)
                    {
                        Debug.Assert(text.TextInfo != null
                        && (text is StaffNameText || text is FramedBarNumberText));

                        if(text is StaffNameText)
                        {
                            _staffNameMetrics = new TextMetrics(graphics, null, text.TextInfo);
                            // move the staffname vertically to the middle of this staff
                            Staff staff = barline.Voice.Staff;
                            float staffheight = staff.Gap * (staff.NumberOfStafflines - 1);
                            float dy = (staffheight * 0.5F) + (gap * 0.8F);
                            _staffNameMetrics.Move(0F, dy);
                        }
                        else if(text is FramedBarNumberText)
                        {
                            _barnumberMetrics = new BarnumberMetrics(graphics, null, text.TextInfo, text.FrameInfo);
                            //_barnumberMetrics = new TextMetrics(graphics, null, text.TextInfo);
                            // move the bar number above this barline
                            float deltaY = (gap * 6F);
                            _barnumberMetrics.Move(0F, -deltaY);
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// noteObjects[noteObjectIndex] is the first OutputChordSymbol or OutputRestSymbol in the tuplet, and is the
        /// noteObject to which the tuplet is attached,
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="tupletDef"></param>
        /// <param name="noteObjects"></param>
        /// <param name="noteObjectIndex"></param>
        public Tuplet(Graphics graphics, TupletDef tupletDef, List <NoteObject> noteObjects, int noteObjectIndex)
            : base(noteObjects[noteObjectIndex])
        {
            List <NoteObject> tupletChordsAndRests = GetTupletChordsAndRests(noteObjects, noteObjectIndex, tupletDef);

            var gap      = M.PageFormat.GapVBPX;
            var textInfo = GetTupletTextInfo(tupletDef.InnerDuration, tupletDef.OuterDuration);

            Metrics = new TextMetrics(CSSObjectClass.tupletText, graphics, textInfo);

            var    textHeight = (Metrics.Bottom - Metrics.Top);
            var    textWidth  = (Metrics.Right - Metrics.Left);
            bool   isOver     = (tupletDef.Orient == Orientation.up);
            double textXAlignment;

            if (tupletChordsAndRests.Count > 2)
            {
                int     alignedIndex = (int)(tupletChordsAndRests.Count) / 2;
                Metrics metrics      = tupletChordsAndRests[alignedIndex].Metrics;
                if (metrics is ChordMetrics cMetrics)
                {
                    textXAlignment = cMetrics.OriginX - textWidth / 4;
                }
                else
                {
                    textXAlignment = ((metrics.Right - metrics.Left) / 2) + metrics.Left;
                }
            }
            else
            {
                M.Assert(tupletChordsAndRests.Count == 2);
                Metrics metrics1 = tupletChordsAndRests[0].Metrics;
                Metrics metrics2 = tupletChordsAndRests[1].Metrics;

                textXAlignment = ((metrics1.Left + metrics2.Right) / 2) - textWidth / 4;
            }

            //textYAlignment = (isOver) ? metrics.Top - gap - (textHeight / 2) : metrics.Bottom + gap + (textHeight / 2);
            double textYAlignment = (isOver) ? double.MaxValue : double.MinValue;;

            foreach (NoteObject noteObject in tupletChordsAndRests)
            {
                var metrics = noteObject.Metrics;
                if (isOver)
                {
                    textYAlignment = (metrics.Top < textYAlignment) ? metrics.Top : textYAlignment;
                }
                else
                {
                    textYAlignment = (metrics.Bottom > textYAlignment) ? metrics.Bottom : textYAlignment;
                }
            }

            #region move vertically off the staff if necessary
            StaffMetrics staffMetrics = tupletChordsAndRests[0].Voice.Staff.Metrics;
            if (isOver)
            {
                double topMax = staffMetrics.StafflinesTop - gap - (textHeight / 2);
                if (textYAlignment > topMax)
                {
                    textYAlignment = topMax;
                }
            }
            else
            {
                double topMin = staffMetrics.StafflinesBottom + gap + (textHeight / 2);
                if (textYAlignment < topMin)
                {
                    textYAlignment = topMin;
                }
            }
            #endregion

            Metrics.Move(textXAlignment, textYAlignment + (textHeight / 2));

            // set auto correctly later -- depends on beaming
            if (tupletDef.Bracket == TupletBracketDisplay.yes || tupletDef.Bracket == TupletBracketDisplay.auto)
            {
                double bracketHoriz  = textYAlignment;
                double bracketLeft   = tupletChordsAndRests[0].Metrics.Left - M.PageFormat.StafflineStemStrokeWidthVBPX;
                double bracketRight  = tupletChordsAndRests[tupletChordsAndRests.Count - 1].Metrics.Right + M.PageFormat.StafflineStemStrokeWidthVBPX;
                double bracketHeight = gap * 0.75;

                _textAndBracketMetrics = new TupletMetrics((TextMetrics)Metrics, bracketHoriz, bracketLeft, bracketRight, bracketHeight, isOver);
            }
        }
Exemplo n.º 15
0
 public OctaveShiftExtenderMetrics(TextMetrics textMetrics, double leftChordLeft, double rightChordRight, double hLineY, string strokeDashArray, double endMarkerHeight,
                                   bool displayEndMarker)
     : base(CSSObjectClass.octaveShiftExtender, textMetrics, leftChordLeft, rightChordRight, hLineY, strokeDashArray, endMarkerHeight, displayEndMarker)
 {
 }
Exemplo n.º 16
0
        public FramedRegionInfoMetrics(Graphics graphics, List <Text> texts, FramePadding framePadding, double gap)
            : base(CSSObjectClass.framedRegionInfo)
        {
            Gap = gap;

            double maxWidth = 0;
            double nextTop  = 0;


            foreach (Text text in texts)
            {
                TextMetrics tm = new TextMetrics(CSSObjectClass.regionInfoString, graphics, text.TextInfo);
                tm.Move(-tm.Left, -tm.Top);
                double width = tm.Right - tm.Left;
                maxWidth = (maxWidth > width) ? maxWidth : width;
                tm.Move(0, nextTop);
                nextTop = tm.Top + ((tm.Bottom - tm.Top) * 1.7);

                _textMetrics.Add(tm);
                _textStrings.Add(text.TextInfo.Text);
            }

            bool alignRight = (texts[0].TextInfo.TextHorizAlign != TextHorizAlign.left);

            if (alignRight)
            {
                foreach (TextMetrics tm in _textMetrics)
                {
                    double deltaX = maxWidth - (tm.Right - tm.Left);
                    tm.Move(deltaX, 0);

                    // move tm.OriginX so that the text is right aligned (OriginX is used by WriteSVG())
                    deltaX = (tm.Right - tm.Left) / 2;
                    tm.Move(-deltaX, 0);
                }
            }
            else // align left
            {
                foreach (TextMetrics tm in _textMetrics)
                {
                    // move tm.OriginX so that the text is left aligned (OriginX is used by WriteSVG())
                    double deltaX = (tm.Right - tm.Left) / 2;
                    tm.Move(deltaX, 0);
                }
            }

            _top    = 0 - framePadding.Top;
            _right  = maxWidth + framePadding.Right;
            _bottom = _textMetrics[_textMetrics.Count - 1].Bottom + framePadding.Bottom;
            _left   = 0 - framePadding.Left;

            switch (texts[0].TextInfo.TextHorizAlign)
            {
            case TextHorizAlign.left:
                Move(-_left, -_bottom);     // set the origin to the bottom left corner
                break;

            case TextHorizAlign.center:
                Move(-((_left + _right) / 2), -_bottom);     // set the origin to the middle of the bottom edge
                break;

            case TextHorizAlign.right:
                Move(-_right, -_bottom);     // set the origin to the bottom right corner
                break;
            }
        }