Exemple #1
0
        public Size MeasureString(FontState state, string text)
        {
            if (text.Length == 0)
            {
                return(Size.Empty);
            }

            int lineLength  = 0;
            int longestLine = 0;
            int lineCount   = 1;
            var fontHeight  = CalcFontHeight(state);

            for (int i = 0; i < text.Length; i++)
            {
                lineLength++;
                if (text[i] == '\n')
                {
                    lineLength = 0;
                    lineCount++;
                }

                longestLine = Math.Max(lineLength, longestLine);
            }

            return(new Size(fontHeight / 2 * longestLine, fontHeight * lineCount));
        }
        private void DrawDistanceResults(object obj)
        {
            int w = 512;
            int h = 256;

            FontState state = (FontState)obj;
            Bitmap    bmp;

            lock (dict)
            {
                bmp = SignedDistanceFieldRenderer.CreateTextureAtlasFromCachedBitmaps(dict, w, h);
            }

            bmp.Save(state.filename, ImageFormat.Png);
            state.s.Stop();

            fontPreview.Invoke((MethodInvoker) delegate
            {
                fontPreview.Image = new Bitmap(bmp);
            });

            statusStrip1.Invoke((MethodInvoker) delegate
            {
                toolStripStatusLabel1.Text = string.Format("Ran for {0} seconds", state.s.ElapsedMilliseconds / 1000.0);
            });
        }
 public PageNumberInlineArea(
     FontState fontState, float red, float green,
     float blue, string refid, int width)
     : base(fontState, red, green, blue, "?", width)
 {
     this.pageNumberId = refid;
 }
Exemple #4
0
 public PageNumberInlineArea(
     FontState fontState, float red, float green,
     float blue, string refid, int width)
     : base(fontState, red, green, blue, "?", width)
 {
     _pageNumberId = refid;
 }
Exemple #5
0
        public override Status Layout(Area area)
        {
            AccessibilityProps mAccProps = propMgr.GetAccessibilityProps();
            AuralProps         mAurProps = propMgr.GetAuralProps();
            BorderAndPadding   bap       = propMgr.GetBorderAndPadding();
            BackgroundProps    bProps    = propMgr.GetBackgroundProps();
            FontState          fontState = propMgr.GetFontState(area.getFontInfo());
            MarginInlineProps  mProps    = propMgr.GetMarginInlineProps();

            Property prop;

            prop = this.properties.GetProperty("baseline-shift");
            if (prop is LengthProperty)
            {
                Length bShift = prop.GetLength();
            }
            else if (prop is EnumProperty)
            {
                int bShift = prop.GetEnum();
            }
            ColorType col       = this.properties.GetProperty("color").GetColorType();
            Length    lHeight   = this.properties.GetProperty("line-height").GetLength();
            int       lShiftAdj = this.properties.GetProperty(
                "line-height-shift-adjustment").GetEnum();
            int    vis    = this.properties.GetProperty("visibility").GetEnum();
            Length zIndex = this.properties.GetProperty("z-index").GetLength();

            return(base.Layout(area));
        }
Exemple #6
0
        static void Main(string[] args)
        {
            FontState fontState = FontState.None;

            while (true)
            {
                Console.WriteLine($"Параметры надписи: {fontState.ToString()}");
                Console.WriteLine("Введите:");
                for (int i = 1; i <= 3; i++)
                {
                    Console.WriteLine($"\t{i}: {GetFont(i)}");
                }
                if (Int32.TryParse(Console.ReadLine(), out int option))
                {
                    if (option > 3 || option < 1)
                    {
                        break;
                    }
                    fontState = fontState ^ GetFont(option);
                }
                else
                {
                    break;
                }
            }
        }
Exemple #7
0
        public override AgateLib.Geometry.Size MeasureString(FontState state, string text)
        {
            Drawing_Display disp            = Display.Impl as Drawing_Display;
            Graphics        g               = disp.FrameGraphics;
            bool            disposeGraphics = false;

            if (g == null)
            {
                g = Graphics.FromImage((disp.RenderTarget.Impl as Drawing_FrameBuffer).BackBufferBitmap);

                disposeGraphics = true;
            }

            SizeF result = new SizeF(g.MeasureString(text, mFont));

            if (disposeGraphics)
            {
                g.Dispose();
            }


            result.Height *= (float)state.ScaleWidth;
            result.Width  *= (float)state.ScaleHeight;

            return(new Geometry.Size((int)result.Width, (int)result.Height));
        }
Exemple #8
0
 /// <inheritdoc />
 public CurrentGraphicsState DeepClone()
 {
     return(new CurrentGraphicsState
     {
         FontState = FontState?.DeepClone(),
         RenderingIntent = RenderingIntent,
         LineDashPattern = LineDashPattern,
         CurrentTransformationMatrix = CurrentTransformationMatrix,
         LineWidth = LineWidth,
         JoinStyle = JoinStyle,
         Overprint = Overprint,
         CapStyle = CapStyle,
         MiterLimit = MiterLimit,
         Flatness = Flatness,
         AlphaConstant = AlphaConstant,
         AlphaSource = AlphaSource,
         NonStrokingOverprint = NonStrokingOverprint,
         OverprintMode = OverprintMode,
         Smoothness = Smoothness,
         StrokeAdjustment = StrokeAdjustment,
         CurrentStrokingColor = CurrentStrokingColor,
         CurrentNonStrokingColor = CurrentNonStrokingColor,
         CurrentClippingPath = CurrentClippingPath
     });
 }
Exemple #9
0
        /// <summary>
        /// Creates a copy of another font with its own state.
        /// </summary>
        /// <param name="prototypeFont"></param>
        public Font(Font prototypeFont)
        {
            Require.ArgumentNotNull(prototypeFont, nameof(prototypeFont));

            core = prototypeFont.Core;

            state = prototypeFont.state.Clone();
        }
Exemple #10
0
 public WordArea(
     FontState fontState, float red, float green,
     float blue, string text, int width)
     : base(fontState, width, red, green, blue)
 {
     this.text = text;
     this.contentRectangleWidth = width;
 }
        public void Reset()
        {
            _state = FontState.NotStarted;
            _text.Clear();
            _currentLetterIndex = -1;

            changeState(FontState.NotStarted);
        }
Exemple #12
0
 public WordArea(
     FontState fontState, float red, float green,
     float blue, string text, int width)
     : base(fontState, width, red, green, blue)
 {
     this.text = text;
     this.contentRectangleWidth = width;
 }
Exemple #13
0
        /// <summary>
        /// Creates a copy of a another font with its own state and style.
        /// </summary>
        /// <param name="prototypeFont"></param>
        /// <param name="style"></param>
        public Font(Font prototypeFont, FontStyles style)
        {
            Require.ArgumentNotNull(prototypeFont, nameof(prototypeFont));

            core = prototypeFont.Core;

            state       = prototypeFont.state.Clone();
            state.Style = style;
        }
Exemple #14
0
 public InlineArea(
     FontState fontState, int width, float red,
     float green, float blue)
     : base(fontState)
 {
     this.contentRectangleWidth = width;
     this.red   = red;
     this.green = green;
     this.blue  = blue;
 }
Exemple #15
0
 public InlineArea(
     FontState fontState, int width, float red,
     float green, float blue)
     : base(fontState)
 {
     this.contentRectangleWidth = width;
     this.red = red;
     this.green = green;
     this.blue = blue;
 }
        public void FFAutoScale()
        {
            var fontState = new FontState();

            fontState.Size  = 9;
            fontState.Style = FontStyles.None;

            var font = ff.Core.FontSurface(fontState);

            Assert.AreEqual(0.9, fontState.ScaleHeight, 0.00001);
        }
        protected virtual void changeState(FontState newState)
        {
            _state = newState;

            EventHandler <StateEventArgs> handler = StateChanged;

            if (handler != null)
            {
                handler(this, new StateEventArgs(typeof(DropInFont.FontState), newState));
            }
        }
Exemple #18
0
 public ImageArea(FontState fontState, FonetImage img, int AllocationWidth,
                  int width, int height, int startIndent, int endIndent,
                  int align)
     : base(fontState, width, 0, 0, 0)
 {
     this.currentHeight         = height;
     this.contentRectangleWidth = width;
     this.height = height;
     this.image  = img;
     this.align  = align;
 }
Exemple #19
0
        public int AddLeader(BlockArea ba, FontState fontState, float red,
                             float green, float blue, int leaderPattern,
                             int leaderLengthMinimum, int leaderLengthOptimum,
                             int leaderLengthMaximum, int ruleThickness,
                             int ruleStyle, int leaderPatternWidth,
                             int leaderAlignment)
        {
            LineArea la = ba.getCurrentLineArea();

            if (la == null)
            {
                return(-1);
            }

            la.changeFont(fontState);
            la.changeColor(red, green, blue);

            if (leaderLengthOptimum <= (la.getRemainingWidth()))
            {
                la.AddLeader(leaderPattern, leaderLengthMinimum,
                             leaderLengthOptimum, leaderLengthMaximum, ruleStyle,
                             ruleThickness, leaderPatternWidth, leaderAlignment);
            }
            else
            {
                la = ba.createNextLineArea();
                if (la == null)
                {
                    return(-1);
                }
                la.changeFont(fontState);
                la.changeColor(red, green, blue);

                if (leaderLengthMinimum <= la.getContentWidth())
                {
                    la.AddLeader(leaderPattern, leaderLengthMinimum,
                                 leaderLengthOptimum, leaderLengthMaximum,
                                 ruleStyle, ruleThickness, leaderPatternWidth,
                                 leaderAlignment);
                }
                else
                {
                    FonetDriver.ActiveDriver.FireFonetWarning(
                        "Leader doesn't fit into line, it will be clipped to fit.");
                    la.AddLeader(leaderPattern, la.getRemainingWidth(),
                                 leaderLengthOptimum, leaderLengthMaximum,
                                 ruleStyle, ruleThickness, leaderPatternWidth,
                                 leaderAlignment);
                }
            }
            return(1);
        }
        public TypingFont(SpriteFont font, Vector2 position, Color color, string textToType, TimeSpan delayTime)
            : base(font, position, color)
        {
            _elapsedDelayTime = TimeSpan.Zero;
            DelayTime = delayTime;
            _currentLetterIndex = -1;

            _textToType = new StringBuilder(textToType);
            _isTextChanged = false;

            _cachedTextTypeSize = _font.MeasureString(textToType);
            _state = FontState.NotStarted;
        }
        public TypingFont(SpriteFont font, Vector2 position, Color color, string textToType, TimeSpan delayTime) :
            base(font, position, color)
        {
            _elapsedDelayTime   = TimeSpan.Zero;
            DelayTime           = delayTime;
            _currentLetterIndex = -1;

            _textToType    = new StringBuilder(textToType);
            _isTextChanged = false;

            _cachedTextTypeSize = _font.MeasureString(textToType);
            _state = FontState.NotStarted;
        }
Exemple #22
0
 // Start is called before the first frame update
 void Start()
 {
     interactables = GetComponentsInChildren <Interactable>();
     Texts         = GetComponentsInChildren <TextMeshPro>();
     animator      = GetComponent <Animator>();
     radView       = GetComponent <RadialView>();
     billBoard     = GetComponent <Billboard>();
     animator.SetBool("isAzerty", isAzerty);
     currentFontState = FontState.Lower;
     if (StartOpen == false)
     {
         Close(false);
     }
 }
Exemple #23
0
 public FontState GetFontState(FontInfo fontInfo)
 {
     if (fontState == null)
     {
         string fontFamily  = properties.GetProperty("font-family").GetString();
         string fontStyle   = properties.GetProperty("font-style").GetString();
         string fontWeight  = properties.GetProperty("font-weight").GetString();
         int    fontSize    = properties.GetProperty("font-size").GetLength().MValue();
         int    fontVariant = properties.GetProperty("font-variant").GetEnum();
         fontState = new FontState(fontInfo, fontFamily, fontStyle,
                                   fontWeight, fontSize, fontVariant);
     }
     return(fontState);
 }
Exemple #24
0
 public LeaderArea(
     FontState fontState, float red, float green,
     float blue, string text, int leaderLengthOptimum,
     int leaderPattern, int ruleThickness, int ruleStyle)
     : base(fontState, leaderLengthOptimum, red, green, blue)
 {
     this.leaderPattern       = leaderPattern;
     this.leaderLengthOptimum = leaderLengthOptimum;
     this.ruleStyle           = ruleStyle;
     if (ruleStyle == RuleStyle.NONE)
     {
         ruleThickness = 0;
     }
     this.ruleThickness = ruleThickness;
 }
Exemple #25
0
 public LeaderArea(
     FontState fontState, float red, float green,
     float blue, string text, int leaderLengthOptimum,
     int leaderPattern, int ruleThickness, int ruleStyle)
     : base(fontState, leaderLengthOptimum, red, green, blue)
 {
     this.leaderPattern = leaderPattern;
     this.leaderLengthOptimum = leaderLengthOptimum;
     this.ruleStyle = ruleStyle;
     if (ruleStyle == RuleStyle.NONE)
     {
         ruleThickness = 0;
     }
     this.ruleThickness = ruleThickness;
 }
Exemple #26
0
        protected static int addRealText(BlockArea ba, FontState fontState,
                                         float red, float green, float blue,
                                         WrapOption wrapOption, LinkSet ls,
                                         int whiteSpaceCollapse, char[] data,
                                         int start, int end, TextState textState,
                                         VerticalAlign vAlign)
        {
            int ts, te;

            char[] ca;

            ts = start;
            te = end;
            ca = data;

            LineArea la = ba.getCurrentLineArea();

            if (la == null)
            {
                return(start);
            }

            la.changeFont(fontState);
            la.changeColor(red, green, blue);
            la.changeWrapOption(wrapOption);
            la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
            la.changeVerticalAlign(vAlign);
            ba.setupLinkSet(ls);

            ts = la.addText(ca, ts, te, ls, textState);

            while (ts != -1)
            {
                la = ba.createNextLineArea();
                if (la == null)
                {
                    return(ts);
                }
                la.changeFont(fontState);
                la.changeColor(red, green, blue);
                la.changeWrapOption(wrapOption);
                la.changeWhiteSpaceCollapse(whiteSpaceCollapse);
                ba.setupLinkSet(ls);

                ts = la.addText(ca, ts, te, ls, textState);
            }
            return(-1);
        }
Exemple #27
0
        public void Run(string[] args)
        {
            using (var wind = new DisplayWindowBuilder(args)
                              .BackbufferSize(800, 600)
                              .QuitOnClose()
                              .Build())
            {
                Input.Unhandled.KeyDown += Keyboard_KeyDown;

                FontState state = new FontState
                {
                    Size  = 14,
                    Style = FontStyles.None,
                };

                FontSurface font = Font.AgateSans.Core.FontSurface(state);

                FontSurface unkerned = ConstructUnkernedFont(font);

                string text = ConstructKerningText(wind, font);

                while (AgateApp.IsAlive)
                {
                    Display.BeginFrame();
                    Display.Clear();

                    FontSurface thisFont = useKerning ? font : unkerned;

                    if (useKerning)
                    {
                        thisFont.DrawText(state, "Using kerning. (space to toggle)");
                    }
                    else
                    {
                        thisFont.DrawText(state, "No kerning used. (space to toggle)");
                    }

                    state.Color = Color.White;
                    thisFont.DrawText(state, new Vector2(0, thisFont.FontHeight(state)), text);

                    Display.EndFrame();
                    AgateApp.KeepAlive();
                }
            }
        }
Exemple #28
0
    public void AddLetter(string value)
    {
        switch (currentFontState)
        {
        case FontState.Lower:
            text += value;
            break;

        case FontState.Upper:
            text            += value.ToUpper();
            currentFontState = FontState.Lower;
            UpperToLower();
            break;

        case FontState.FullUpper:
            text += value.ToUpper();
            break;
        }
    }
        public void Reset()
        {
            _state = FontState.Fading;
            _alpha = _startingAlpha;

            if (_fadeType == FadingType.In)
            {
                _targetTintColor = _startingTintColor;
                _tintColor       = Color.Transparent;

                _targetShadowColor = _startingShadowColor;
                _shadowColor       = Color.Transparent;
            }
            else
            {
                _targetTintColor   = Color.Transparent;
                _targetShadowColor = Color.Transparent;
            }
        }
Exemple #30
0
        static void Main(string[] args)
        {
            FontState fontType = 0;
            string    input;
            int       font;

            do
            {
                Console.WriteLine("Font parameters: {0}", fontType.ToString());
                Console.WriteLine("Input:\n" +
                                  "     1: bold\n" +
                                  "     2: italic\n" +
                                  "     3: underline");
                //Console.WriteLine("     exit: for exit");
                input = Console.ReadLine();

                if ((int.TryParse(input, out font)) && (font > 0) && (font < 4))
                {
                    switch (font)
                    {
                    case 1: fontType ^= FontState.Bold; break;

                    case 2: fontType ^= FontState.Italic; break;

                    case 3: fontType ^= FontState.Underline; break;
                    }
                }
                else
                {
                    if (input.Equals("exit"))
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Incorrect input");
                    }
                }
            } while (!(input.Equals("exit")));
        }
        private void RenderDistanceFieldForAsciiChar(object obj)
        {
            FontState state = (FontState)obj;

            Bitmap bmp = SignedDistanceFieldRenderer.RenderDistanceFieldForChar(
                state.glyph, state.font, 256, 256, state.interpolation);

            lock (dict)
            {
                dict[state.glyph] = bmp;
            }

            statusStrip1.Invoke((MethodInvoker) delegate
            {
                progressBar1.PerformStep();
            });

            if (Interlocked.Increment(ref counter) > state.range)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(DrawDistanceResults), obj);
            }
        }
Exemple #32
0
        public override void DrawText(FontState state)
        {
            Geometry.PointF shift = Origin.CalcF(state.DisplayAlignment,
                                                 MeasureString(state, state.Text));

            PointF dest_pt = Interop.Convert(state.Location);

            dest_pt.X -= shift.X;
            dest_pt.Y -= shift.Y;

            Drawing_Display disp = Display.Impl as Drawing_Display;
            Graphics        g    = disp.FrameGraphics;

            GraphicsState g_state = g.Save();
            double        scalex = state.ScaleWidth, scaley = state.ScaleHeight;

            g.TranslateTransform(dest_pt.X, dest_pt.Y);
            g.ScaleTransform((float)scalex, (float)scaley);

            g.DrawString(state.Text, mFont,
                         new SolidBrush(Interop.Convert(state.Color)), Point.Empty);

            g.Restore(g_state);
        }
Exemple #33
0
 public ForeignObjectArea(FontState fontState, int width)
     : base(fontState, width, 0, 0, 0)
 {
 }
Exemple #34
0
        /**
         * render inline area to PDF
         *
         * @param area inline area to render
         */
        public void RenderWordArea(WordArea area)
        {
            FontState fontState = area.GetFontState();
            String    name      = fontState.FontName;
            int       size      = fontState.FontSize;
            // This assumes that *all* CIDFonts use a /ToUnicode mapping
            Font font = (Font)fontState.FontInfo.GetFontByName(name);

            if ((!name.Equals(this.currentFontName)) ||
                (size != this.currentFontSize))
            {
                CloseText();

                this.currentFontName = name;
                this.currentFontSize = size;

                currentStream.SetFont(name, size);
            }

            // Do letter spacing (must be outside of [...] TJ]
            float letterspacing = ((float)fontState.LetterSpacing) / 1000f;

            if (letterspacing != this.currentLetterSpacing)
            {
                this.currentLetterSpacing = letterspacing;
                CloseText(); //?
                currentStream.SetLetterSpacing(letterspacing);
            }

            //--------------------------------------------
            PdfColor?a_color       = this.currentFill;
            PdfColor areaObj_color = area.GetColor();

            if (a_color == null || !areaObj_color.IsEq(a_color.Value))
            {
                //change area color
                a_color = areaObj_color;

                CloseText(); //?
                this.currentFill = a_color;
                currentStream.SetFontColor(a_color.Value);
            }
            //--------------------------------------------

            int rx           = this.currentXPosition;
            int bl           = this.currentYPosition;
            int areaContentW = area.getContentWidth();

            if (area.getUnderlined())
            {
                AddUnderLine(rx, bl, areaContentW, size, a_color.Value);
            }
            if (area.getOverlined())
            {
                AddOverLine(rx, bl, areaContentW, size, fontState.Ascender, a_color.Value);
            }
            if (area.getLineThrough())
            {
                AddLineThrough(rx, bl, areaContentW, size, fontState.Ascender, a_color.Value);
            }
            //--------------------------------------------


            _textPrinter.Reset(fontState, options != null && options.Kerning);
            if (!textOpen || bl != prevWordY)
            {
                CloseText();
                //set text matrix


                _textPrinter.SetTextPos(rx, bl);
                //pdf.Append("1 0 0 1 " + PdfNumber.doubleOut(rx / 1000f) +
                //    " " + PdfNumber.doubleOut(bl / 1000f) + " Tm [" + startText);
                prevWordY = bl;
                textOpen  = true; //***
            }
            else
            {
                // express the space between words in thousandths of an em
                int   space  = prevWordX - rx + prevWordWidth;
                float emDiff = (float)space / (float)currentFontSize * 1000f;
                // this prevents a problem in Acrobat Reader where large
                // numbers cause text to disappear or default to a limit
                if (emDiff < -33000)
                {
                    CloseText();
                    _textPrinter.SetTextPos(rx, bl);
                    //pdf.Append("1 0 0 1 " + PdfNumber.doubleOut(rx / 1000f) +
                    //    " " + PdfNumber.doubleOut(bl / 1000f) + " Tm [" + startText);
                    textOpen = true;//***
                }
                else
                {
                    _textPrinter.SetEmDiff(emDiff);
                    //pdf.Append(PdfNumber.doubleOut(emDiff));
                    //pdf.Append(" ");
                    //pdf.Append(startText);
                }
            }

            prevWordWidth = areaContentW;
            prevWordX     = rx;

            string s = area.GetTextContent();

            if (area is PageNumberInlineArea)
            {
                //need to resolve to page number
                s = idReferences.getPageNumber(s);
            }
            _textPrinter.WriteText(s);
            //-------
            _textPrinter.PrintContentTo(currentStream);
            //-------
            this.currentXPosition += area.getContentWidth();
        }
        public void Reset()
        {
            _state = FontState.NotStarted;
            _text.Clear();
            _currentLetterIndex = -1;

            changeState(FontState.NotStarted);
        }
Exemple #36
0
 public IFontTexture FontSurface(FontState fontState)
 {
     throw new NotImplementedException();
 }
Exemple #37
0
 public void DrawText(FontState state, Vector2 dest, string text, params object[] parameters)
 {
     LogDrawText(dest, state.Color, text);
 }
        protected virtual void changeState(FontState newState)
        {
            _state = newState;

            EventHandler<StateEventArgs> handler = StateChanged;
            if (handler != null)
            {
                handler(this, new StateEventArgs(typeof(SlidingFont.FontState), newState));
            }
        }
        public void Reset()
        {
            _state = FontState.Fading;
            _alpha = _startingAlpha;

            if (_fadeType == FadingType.In)
            {
                _targetTintColor = _startingTintColor;
                _tintColor = Color.Transparent;

                _targetShadowColor = _startingShadowColor;
                _shadowColor = Color.Transparent;
            }
            else
            {
                _targetTintColor = Color.Transparent;
                _targetShadowColor = Color.Transparent;
            }
        }