Exemple #1
0
 private TopEdge GetTopEdge(int lowerStaffIndex, float pageWidth)
 {
     TopEdge topEdge = null;
     for(int i = lowerStaffIndex; i < Staves.Count; ++i)
     {
         Staff staff = Staves[i];
         if(!(staff is HiddenOutputStaff) && staff.Metrics != null)
         {
             topEdge = new TopEdge(staff, 0F, pageWidth);
             break;
         }
     }
     return topEdge;
 }
Exemple #2
0
        private void JustifyVertically(float pageWidth, float gap)
        {
            int barnumberStaffIndex = BarnumberStaffIndex();
            float stafflinesTop = Staves[barnumberStaffIndex].Metrics.StafflinesTop;
            if(stafflinesTop != 0)
            {
                for(int i = barnumberStaffIndex; i < Staves.Count; ++i)
                {
                    Staff staff = Staves[i];
                    if(staff.Metrics != null)
                    {
                        staff.Metrics.Move(0, stafflinesTop * -1);
                    }
                }
            }

            Debug.Assert(Staves[barnumberStaffIndex].Metrics.StafflinesTop == 0);
            if((barnumberStaffIndex + 1) < Staves.Count)// There must be at least one visible staff (an InputStaff).
            {
                for(int i = (barnumberStaffIndex + 1); i < Staves.Count; ++i)
                {
                    if(Staves[i].Metrics != null)
                    {
                        //BottomEdge bottomEdge = new BottomEdge(Staves[i - 1], 0F, pageWidth, gap);
                        BottomEdge bottomEdge = GetBottomEdge(i - 1, barnumberStaffIndex, pageWidth, gap);
                        if(bottomEdge != null)
                        {
                            TopEdge topEdge = new TopEdge(Staves[i], 0F, pageWidth);
                            float separation = topEdge.DistanceToEdgeAbove(bottomEdge);
                            float dy = gap - separation;
                            // limit stafflineHeight to multiples of pageFormat.Gap so that stafflines
                            // are not displayed as thick grey lines.
                            dy = dy - (dy % gap) + gap; // the minimum space bewteen stafflines is gap pixels.
                            if(dy > 0F)
                            {
                                for(int j = i; j < Staves.Count; ++j)
                                {
                                    if(Staves[j].Metrics != null)
                                    {
                                        Staves[j].Metrics.Move(0F, dy);
                                    }
                                }
                                this.Metrics.StafflinesBottom += dy;
                            }
                        }
                    }
                }
            }
            this.Metrics = new SystemMetrics();
            foreach(Staff staff in Staves)
            {
                if(!(staff is HiddenOutputStaff) && staff.Metrics != null)
                {
                    this.Metrics.Add(staff.Metrics);
                }
            }
            Debug.Assert(this.Metrics.StafflinesTop == 0);
        }
Exemple #3
0
        private void WriteConnectors(SvgWriter w, int systemNumber, PageFormat pageFormat)
        {
            List<bool> barlineContinuesDownList = pageFormat.BarlineContinuesDownList;
            int topVisibleStaffIndex = TopVisibleStaffIndex();
            Debug.Assert(barlineContinuesDownList.Count == Staves.Count - topVisibleStaffIndex);
            Debug.Assert(barlineContinuesDownList[barlineContinuesDownList.Count - 1] == false);
            Barline barline = null;
            bool isFirstBarline = true;

            for(int staffIndex = topVisibleStaffIndex; staffIndex < Staves.Count; staffIndex++)
            {
                Staff staff = Staves[staffIndex];
                Voice voice = staff.Voices[0];
                float barlinesTop = staff.Metrics.StafflinesTop;
                float barlinesBottom = staff.Metrics.StafflinesBottom;

                #region set barlinesTop, barlinesBottom
                switch(staff.NumberOfStafflines)
                {
                    case 1:
                        barlinesTop -= (staff.Gap * 1.5F);
                        barlinesBottom += (staff.Gap * 1.5F);
                        break;
                    case 2:
                    case 3:
                    case 4:
                        barlinesTop -= staff.Gap;
                        barlinesBottom += staff.Gap;
                        break;
                    default:
                        break;
                }
                #endregion set barlinesTop, barlinesBottom

                #region draw barlines down from staves
                if(staffIndex < Staves.Count - 1)
                {
                    BottomEdge bottomEdge = new BottomEdge(staff, 0F, pageFormat.Right, pageFormat.Gap);
                    TopEdge topEdge = new TopEdge(Staves[staffIndex + 1], 0F, pageFormat.Right);
                    isFirstBarline = true;

                    for(int i = 0; i < voice.NoteObjects.Count; ++i)
                    {
                        NoteObject noteObject = voice.NoteObjects[i];
                        barline = noteObject as Barline;
                        if(barline != null)
                        {
                            // draw grouping barlines between staves
                            if(barlineContinuesDownList[staffIndex - topVisibleStaffIndex] || isFirstBarline)
                            {
                                float top = bottomEdge.YatX(barline.Metrics.OriginX);
                                float bottom = topEdge.YatX(barline.Metrics.OriginX);
                                bool isLastNoteObject = (i == (voice.NoteObjects.Count - 1));
                                barline.WriteSVG(w, top, bottom, pageFormat.BarlineStrokeWidth, pageFormat.StafflineStemStrokeWidth, isLastNoteObject, true);
                                isFirstBarline = false;
                            }
                        }
                    }
                }
                #endregion
            }
        }