Exemplo n.º 1
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);
        }