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; }
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); } } } } }
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); }
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); } } } } }
/// <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); } }
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; } }