示例#1
0
        public void btnChoose_Click(object sender, EventArgs e)
        {
            List <Shape> shapes = Shape.FlattenList(Globals.SelectedOrCurrentShapes(), Shape.FlatListPurpose.Style);
            // this reads the font out of the first suitable object it can find
            Font font = null;

            foreach (Shape shape in shapes)
            {
                if (shape.StyleObjectForParameter(Parameters.FontSize) is Shape.TextStyleC style)
                {
                    // this shape supports font style
                    font = style.CreateFont(style.Size);
                    break;
                }
            }
            using (frmFont frm = new frmFont())
            {
                if (font != null)
                {
                    frm.SelectedFont = font;
                }
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    Globals.RestoreFocus();
                    return;
                }
                font = frm.SelectedFont;
            }
            // Now apply this fonts to all applicable selected objects
            Transaction transaction = new Transaction();

            foreach (Shape shape in shapes)
            {
                if (shape.StyleObjectForParameter(Parameters.FontSize) is Shape.TextStyleC style)
                {
                    transaction.Edit(shape);
                    int oldSize = style.ParameterValue(Parameters.FontSize);
                    style.ApplyFont(font);
                    shape.NotifyStyleChanged(Parameters.FontSize, oldSize, (int)(font.Size * 100));
                    // this allows the shape to update its bounding box. Parameter FontSize just lets it know that the font has changed
                }
            }
            Globals.SetFontAsDefault(font);
            Globals.Root.StoreNewTransaction(transaction, true);
            //m_ctrGUI.NotifyExternalChangesToSelected(objTransaction)
            Globals.RestoreFocus();
        }
示例#2
0
 private void btnFont_Click(object sender, EventArgs e)
 {
     using (frmFont frm = new frmFont())
     {
         Font font = m_Items.First().TextStyle?.CreateFont(m_Items.First().TextStyle.Size);
         if (font != null)
         {
             frm.SelectedFont = font;
         }
         if (frm.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         foreach (Item i in m_Items)
         {
             i.TextStyle.ApplyFont(frm.SelectedFont);
         }
         Updated();
     }
 }