示例#1
0
        internal LedFont Create(string name, string systemName, IEnumerable <string> searchNames, string fontFamily, int fontSize, int fontWeight, AntialiasFormat antialiasFormat)
        {
            int fontIndex = calculatorGateway.RegisterFont(fontFamily, fontSize, fontWeight, antialiasFormat);

            int ascent = calculatorGateway.GetStringAscent(fontIndex);
            int height = calculatorGateway.GetStringHeight(fontIndex);

            return(new LedFont(name, systemName, searchNames, fontIndex, ascent, height));
        }
示例#2
0
        public void RegisterBitmap(CalculatorGateway calculatorGateway)
        {
            HasFlashElement = Text.Any(e => e.Flash);

            if (IsAutoWidth)
            {
                int width = 0;

                foreach (IRichTextElement element in Text)
                {
                    if (element is Run)
                    {
                        Run run = (Run)element;
                        if (run.InnerText != "")
                        {
                            width += calculatorGateway.GetStringWidth(run.InnerText, run.Font.FontIndex);
                        }
                    }
                    else if (element is Image)
                    {
                        Image image = (Image)element;
                        width += image.DrawWidth;
                    }
                }

                Width = width;
            }

            byte[] stableBitmap = new byte[Width * Height * 3];
            calculatorGateway.ClearDots(stableBitmap, Width, Height);

            byte[] flashBitmap = new byte[Width * Height * 3];
            calculatorGateway.ClearDots(flashBitmap, Width, Height);

            List <int> stopPositions = new List <int>();

            if (!(BiggestFont is null))
            {
                int ascent = calculatorGateway.GetStringAscent(BiggestFont.FontIndex);
                int y      = Height - calculatorGateway.GetStringHeight(BiggestFont.FontIndex);

                int x = 0;
                foreach (IRichTextElement element in Text)
                {
                    if (x >= Width)
                    {
                        break;
                    }

                    if (element is Run)
                    {
                        Run run = (Run)element;
                        if (run.InnerText != "")
                        {
                            calculatorGateway.WriteStringToDots(
                                run.Flash ? flashBitmap : stableBitmap,
                                run.InnerText, run.Font.FontIndex, run.FontColor, run.BackgroundColor,
                                x, BiggestFont.FontIndex == run.Font.FontIndex ? y : y + ascent - calculatorGateway.GetStringAscent(run.Font.FontIndex),
                                Width, Height);
                            x += calculatorGateway.GetStringWidth(run.InnerText, run.Font.FontIndex);
                        }
                    }
                    else if (element is Image)
                    {
                        Image image = (Image)element;
                        calculatorGateway.WriteImageToDots(
                            image.Flash ? flashBitmap : stableBitmap, image.Bitmap,
                            x, Height - image.DrawHeight,
                            image.Width, image.Height,
                            image.DrawWidth, image.DrawHeight,
                            Width, Height,
                            image.XIndex, image.YIndex,
                            false);
                        x += image.DrawWidth;
                    }
                    else if (element is Stop)
                    {
                        stopPositions.Add(x);
                    }
                }
            }

            StableBitmap  = stableBitmap;
            FlashBitmap   = flashBitmap;
            StopPositions = stopPositions.AsReadOnly();

            HasBitmapRegistered = true;
        }