Esempio n. 1
0
    public static float Convert(GraphicsUnit fromUnits, GraphicsUnit toUnits, float dpi, float value) {
      float f1 = value;
      if (fromUnits != toUnits) {
        float f2;

        GraphicsUnit graphicsUnit;

        if (fromUnits == GraphicsUnit.Pixel) {
          graphicsUnit = GraphicsUnit.Inch;
          f2 = value / dpi;
        } else {
          f2 = value;
          graphicsUnit = fromUnits;
        }
        if (graphicsUnit == toUnits) {
          f1 = f2;
        } else if (toUnits == GraphicsUnit.Pixel) {
          if (graphicsUnit != GraphicsUnit.Inch) {
            int i = GraphicsUnitIndex(graphicsUnit);
            int j = GraphicsUnitIndex(GraphicsUnit.Inch);
            f2 *= conversionRatios[i, j];
          }
          f1 = f2 * dpi;
        } else {
          int i = GraphicsUnitIndex(graphicsUnit);
          int j = GraphicsUnitIndex(toUnits);
          f1 = f2 * conversionRatios[i, j];
        }
      }
      return f1;
    }
	// Constructor, which saves away all of the important information.
	// We assume that the lock on the "graphics" object is held by the caller.
	internal GraphicsContainer(Graphics graphics)
			{
				// Push this container onto the stack.
				this.graphics = graphics;
				next = graphics.stackTop;
				graphics.stackTop = this;

				// Save the graphics state information.
				clip = graphics.Clip;
				if(clip != null)
				{
					clip = clip.Clone();
				}
				compositingMode = graphics.CompositingMode;
				compositingQuality = graphics.CompositingQuality;
				interpolationMode = graphics.InterpolationMode;
				pageScale = graphics.PageScale;
				pageUnit = graphics.PageUnit;
				pixelOffsetMode = graphics.PixelOffsetMode;
				renderingOrigin = graphics.RenderingOrigin;
				smoothingMode = graphics.SmoothingMode;
				textContrast = graphics.TextContrast;
				textRenderingHint = graphics.TextRenderingHint;
				if (graphics.transform == null)
				{
					transform = null;
				}
				else
				{
					transform = Matrix.Clone(graphics.transform);
				}
			}
Esempio n. 3
0
 public CreateFontArgs(string name, float size, FontStyle style, GraphicsUnit unit)
 {
     Name = String.IsNullOrWhiteSpace(name) ? FontFactory.GenericSansSerif : name;
     Size = size;
     Style = style;
     Unit = unit;
 }
Esempio n. 4
0
 public FontInfo(string name, float size, FontStyle style, GraphicsUnit unit)
 {
     Name = name;
     Size = size;
     Style = style;
     Unit = unit;
 }
 private void Init(Font font)
 {
     FontFamily = font.FontFamily.Name;
     GraphicsUnit = font.Unit;
     Size = font.Size;
     Style = font.Style;
 }
Esempio n. 6
0
        public static decimal ConvertValue(GraphicsUnit from, GraphicsUnit to, decimal value)
        {
            if (from == to)
                return value;

            // 先转为中立的单位 1/100 英寸
            double middle = 0;

            // Specifies the unit of measure of the display device. Typically pixels for video displays, and 1/100 inch for printers.
            if (from == GraphicsUnit.Display)
                middle = (double)value; // 1/100 英寸不变
            // Specifies the document unit (1/300 inch) as the unit of measure.
            if (from == GraphicsUnit.Document)
                middle = (double)value / (double)3; // 1/300 英寸 --> 1/100 英寸不变
            if (from == GraphicsUnit.Inch)
                middle = (double)value * (double)100; // 1 英寸 --> 1/100 英寸不变
            if (from == GraphicsUnit.Millimeter)
                middle = (double)value / (double)0.254; //  毫米 --> 1/100 英寸
            // Specifies a printer's point (1/72 inch) as the unit of measure.
            if (from == GraphicsUnit.Point)
                middle = (double)value * (double)72 / (double)100;    // 1 / 72 英寸 1/100 英寸

            if (to == GraphicsUnit.Display)
                return (decimal)middle;  // 1/100 英寸 --> 1/100 英寸
            if (to == GraphicsUnit.Document)
                return (decimal)(middle * (double)3); // 1/100 英寸 -> 1/300 英寸
            if (to == GraphicsUnit.Inch)
                return (decimal)(middle / (double)100);   // 1/100 英寸 --> 英寸
            if (to == GraphicsUnit.Millimeter)
                return (decimal)(middle * (double)0.254);  // 1/100 英寸 --> 毫米
            if (to == GraphicsUnit.Point)
                return (decimal)(middle * (double)100 / (double)72);  // 1/100 英寸 --> 1 / 72 英寸

            throw new Exception("尚未实现");
        }
 public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit)
 {
     this.FontFamily = new FontFamily(familyName); //Drawing.FontFamily.GenericSansSerif;
     this.Size = (int)emSize;
     this.Style = style;
     this.Name = familyName;
 }
Esempio n. 8
0
File: Font.cs Progetto: LevNNN/mono
		private void CreateFont (string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical)
		{
#if ONLY_1_1
			if (familyName == null)
				throw new ArgumentNullException ("familyName");
#endif
			originalFontName = familyName;
                        FontFamily family;
			// NOTE: If family name is null, empty or invalid,
			// MS creates Microsoft Sans Serif font.
			try {
				family = new FontFamily (familyName);
			}
			catch (Exception){
				family = FontFamily.GenericSansSerif;
			}

			setProperties (family, emSize, style, unit, charSet, isVertical);           
			Status status = GDIPlus.GdipCreateFont (family.NativeObject, emSize,  style, unit, out fontObject);
			
			if (status == Status.FontStyleNotFound)
				throw new ArgumentException (Locale.GetText ("Style {0} isn't supported by font {1}.", style.ToString (), familyName));
				
			GDIPlus.CheckStatus (status);
		}
Esempio n. 9
0
        /// <summary>
        /// Scales sizes to device units
        /// </summary>
        /// <param name="size"></param>
        /// <param name="unit"></param>
        /// <param name="g"></param>
        /// <returns></returns>
        public static float ScaleSizeToDeviceUnits(float size, GraphicsUnit unit, Graphics g)
        {
            if (unit == g.PageUnit)
                return size;

            switch (unit)
            {
                case GraphicsUnit.Point:
                    size *= g.DpiY / 72f;
                    break;
                case GraphicsUnit.Display:
                    //Heuristic for printer or display needed!
                    size *= g.DpiY / (g.DpiY < 100 ? 72f : 100f) ;
                    break;
                case GraphicsUnit.Document:
                    size *= g.DpiY / 300;
                    break;
                case GraphicsUnit.Inch:
                    size *= g.DpiY;
                    break;
                case GraphicsUnit.Millimeter:
                    size *= g.DpiY / 25.4f;
                    break;
                case GraphicsUnit.World:
                    size *= g.DpiY / g.PageScale;
                    break;
                    /*
                case GraphicsUnit.Pixel:
                default:
                    //do nothing
                    break;
                 */
            }
            return (float) Math.Round(size, MidpointRounding.AwayFromZero);
        }
Esempio n. 10
0
		internal static float getTableHeaderOffset(GraphicsUnit unit)
		{
			switch (unit)
			{

				case GraphicsUnit.Millimeter:
					return 3.2f;

				case GraphicsUnit.Inch:
					return 1.0f / 6;

				case GraphicsUnit.Point:
					return 72.0f / 6;

				case GraphicsUnit.Pixel:
					return 12;

				case GraphicsUnit.Document:
					return 300.0f / 6;

				case GraphicsUnit.Display:
					return 75.0f / 6;

			}

			return 2;
		}
Esempio n. 11
0
    private static int GraphicsUnitIndex(GraphicsUnit graphicsUnit) {
      int i = -1;
      switch (graphicsUnit) {
        case GraphicsUnit.Display:
          i = 0;
          break;

        case GraphicsUnit.Document:
          i = 1;
          break;

        case GraphicsUnit.Inch:
          i = 2;
          break;

        case GraphicsUnit.Millimeter:
          i = 3;
          break;

        case GraphicsUnit.Point:
          i = 4;
          break;
      }
      return i;
    }
 /// <summary>
 /// Creates a new instance of FeatureSymbolizer
 /// </summary>
 protected FeatureSymbolizer()
 {
     _scaleMode = ScaleModes.Simple;
     _smoothing = true;
     _isVisible = true;
     _unit = GraphicsUnit.Pixel;
 }
Esempio n. 13
0
			public ItemKey(string name, float size, FontStyle style, GraphicsUnit unit)
			{
				Name = name;
				//So we don't end up with an insane # of items.
				Size = (float) Math.Round(size*10)/10;
				Style = style;
				Unit = unit;
			}
Esempio n. 14
0
 public __Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet)
 {
     this.Name = familyName;
     this.Size = emSize;
     this._style = style;
     this._unit = unit;
     this._gdiCharSet = gdiCharSet;
 }
Esempio n. 15
0
		public static Font CreateFont(string strFamily, float fEmSize, FontStyle fs,
			GraphicsUnit gu)
		{
			try { return new Font(strFamily, fEmSize, fs, gu); }
			catch(Exception) { Debug.Assert(false); } // Style unsupported?

			return new Font(strFamily, fEmSize, gu); // Regular style
		}
Esempio n. 16
0
        public static Font CreateFont(byte[] ByteFont, float emSize, FontStyle Style, GraphicsUnit Unit = GraphicsUnit.Pixel)
        {
            IntPtr Buffer = Marshal.AllocCoTaskMem(ByteFont.Length);
            Marshal.Copy(ByteFont, 0, Buffer, ByteFont.Length);
            Fonts.AddMemoryFont(Buffer, ByteFont.Length);

            return new Font(Fonts.Families[Fonts.Families.Length - 1], emSize, Style, Unit);
        }
Esempio n. 17
0
		public Font LoadFont(string fontName, int size, FontStyle style, GraphicsUnit unit)
		{
			try {
				return new Font(fontName, size, style, unit);
			} catch (Exception) {
				return SystemInformation.MenuFont;
			}
		}
Esempio n. 18
0
 public static Font Create(
     string family,
     float emSize,
     FontStyle style = FontStyle.Regular,
     GraphicsUnit unit = GraphicsUnit.Pixel)
 {
     var fam = GetFamily(family);
     return new Font(family, emSize, style, unit);
 }
Esempio n. 19
0
        public static string GetUnitString(GraphicsUnit unit)
        {
            if (unit == GraphicsUnit.Display)
                return "1/100 英寸";
            if (unit == GraphicsUnit.Millimeter)
                return "毫米";

            return unit.ToString();
        }
Esempio n. 20
0
        public AceFont(Font f)
        {
            if(f == null) throw new ArgumentNullException("f");

            this.Family = f.FontFamily.Name;
            m_fSize = f.Size;
            m_fStyle = f.Style;
            m_gu = f.Unit;
        }
 public void DrawImage(Bitmap bitmap, Rectangle target, Rectangle source, GraphicsUnit gu)
 {
     this.paint.Flags = 0;
     using (Rect sa = source.ToRect())
     using (Rect ta = target.ToRect())
     {
         this.canvas.DrawBitmap(bitmap, sa, ta, this.paint);
     }
 }
Esempio n. 22
0
 public Font()
 {
   System.Drawing.Font tempFont = new System.Drawing.Font("Arial", 10.0F, GraphicsUnit.Millimeter);
   familyName = tempFont.FontFamily.Name;
   emSize = tempFont.Size;
   style = tempFont.Style;
   unit = tempFont.Unit;
   gdiCharSet = tempFont.GdiCharSet;
   gdiVerticalFont = tempFont.GdiVerticalFont;
 }
Esempio n. 23
0
 public static float ConvertEmToPixels(float em, GraphicsUnit unit, double dpi)
 {
     switch (unit)
     {
         case GraphicsUnit.Point: //pt
             return (float) ConvertPtToPixel(em/72f, dpi);
         default:
             return em;
     }
 }
Esempio n. 24
0
			public ItemKey(string name, float size, FontStyle style, GraphicsUnit unit)
			{
				Name = name;
				//So we don't end up with an insane # of items.
			    _sizeEquality = (int)Math.Round(size*10);
				Size = _sizeEquality/10F;
				Style = style;
				Unit = unit;
			    _hash = ComputeHash();
			}
Esempio n. 25
0
	// Constructor.
	internal Graphics(IToolkitGraphics graphics)
			{
				this.graphics = graphics;
				this.clip = null;
				this.transform = null;
				this.pageScale = 1.0f;
				this.pageUnit = GraphicsUnit.World;
				this.stackTop = null;
				this.baseWindow = Rectangle.Empty;
			}
 public void DrawImage(Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
 {
     if (image == null)
         throw new ArgumentNullException ("image");
     throw new NotImplementedException ();
     //Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
     //	destRect.X, destRect.Y, destRect.Width, destRect.Height,
     //	srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
     //	srcUnit, IntPtr.Zero, null, IntPtr.Zero);
     //GDIPlus.CheckStatus (status);
 }
        public Font ResolveFont(string familyName, float emSize, FontStyle fontStyle, GraphicsUnit unit)
        {
            Font fontTester = new Font(familyName, emSize, fontStyle, unit);
            if (fontTester.Name == familyName || !TryResolve(ref familyName, ref fontStyle) )
            {
                return fontTester;
            }
            fontTester.Dispose();

            FontFamily fontFamily = GetFontFamily(familyName);
            return new Font(fontFamily, emSize, fontStyle, unit);
        }
Esempio n. 28
0
	static void DrawTestString (Graphics g, GraphicsUnit unit)
	{
		g.PageUnit = unit;
		float left = 50;
		float top = 50;
		float height = 10;

		g.DrawLine (Pens.Black, left, top, left, top + height);
		g.DrawLine (Pens.Black, left, top + height, left + height, top + height);

		Font font = new Font ("Arial", height, unit);
		g.DrawString ("Xyz| unit: " + unit.ToString (), font, Brushes.Black, left, top);
	}
Esempio n. 29
0
        public Font(FontFamily familyName, float emSize, FontStyle style,
		             GraphicsUnit unit, byte gdiCharSet, bool  gdiVerticalFont )
        {
            if (emSize <= 0)
                throw new ArgumentException("emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.","emSize");

            fontFamily = familyName;
            fontStyle = style;
            this.gdiVerticalFont = gdiVerticalFont;
            this.gdiCharSet = gdiCharSet;

            CreateNativeFont (familyName, emSize, style, unit, gdiCharSet, gdiVerticalFont);
        }
Esempio n. 30
0
 public Font(float sizeInMM)
 {
   System.Drawing.Font tempFont = new System.Drawing.Font("Arial", sizeInMM, GraphicsUnit.Millimeter);
   familyName = tempFont.FontFamily.Name;
   if (sizeInMM > 0.0F)
     emSize = sizeInMM;
   else
     emSize = 3.0F;
   style = tempFont.Style;
   unit = GraphicsUnit.Millimeter;
   gdiCharSet = tempFont.GdiCharSet;
   gdiVerticalFont = tempFont.GdiVerticalFont;
 }
Esempio n. 31
0
 public void DrawImage(Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
 {
     this.surface.StretchImage(destRect.X, destRect.Y, destRect.Width, destRect.Height, image.data.surface, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, (ushort)byte.MaxValue);
 }
Esempio n. 32
0
 internal static extern int GdipGetImageBounds(HandleRef image, out RectangleF gprectf, out GraphicsUnit unit);
Esempio n. 33
0
File: GL2.cs Progetto: 894880010/MP
 public void DrawImage(Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
 {
     throw new NotImplementedException();
 }
Esempio n. 34
0
 internal static extern int GdipEnumerateMetafileSrcRectDestPointsI(HandleRef graphics, HandleRef metafile, Point *destPoints, int count, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
Esempio n. 35
0
        internal void unitConversion(GraphicsUnit fromUnit, GraphicsUnit toUnit, float nSrc, out float nTrg)
        {
            float inchs = 0;

            nTrg = 0;

            switch (fromUnit)
            {
            case GraphicsUnit.Display:
                inchs = nSrc / 75f;
                break;

            case GraphicsUnit.Document:
                inchs = nSrc / 300f;
                break;

            case GraphicsUnit.Inch:
                inchs = nSrc;
                break;

            case GraphicsUnit.Millimeter:
                inchs = nSrc / 25.4f;
                break;

            case GraphicsUnit.Pixel:
            case GraphicsUnit.World:
                inchs = nSrc / Graphics.systemDpiX;
                break;

            case GraphicsUnit.Point:
                inchs = nSrc / 72f;
                break;

            default:
                throw new ArgumentException("Invalid GraphicsUnit");
            }

            switch (toUnit)
            {
            case GraphicsUnit.Display:
                nTrg = inchs * 75;
                break;

            case GraphicsUnit.Document:
                nTrg = inchs * 300;
                break;

            case GraphicsUnit.Inch:
                nTrg = inchs;
                break;

            case GraphicsUnit.Millimeter:
                nTrg = inchs * 25.4f;
                break;

            case GraphicsUnit.Pixel:
            case GraphicsUnit.World:
                nTrg = inchs * Graphics.systemDpiX;
                break;

            case GraphicsUnit.Point:
                nTrg = inchs * 72;
                break;

            default:
                throw new ArgumentException("Invalid GraphicsUnit");
            }
        }
Esempio n. 36
0
File: GL2.cs Progetto: 894880010/MP
 public void DrawImage(Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit)
 {
     throw new NotImplementedException();
 }
Esempio n. 37
0
File: GL2.cs Progetto: 894880010/MP
 public void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
 {
     throw new NotImplementedException();
 }
Esempio n. 38
0
        private void GetImageForPrint(object sender, PrintPageEventArgs e)
        {
            ContentAlignment alignment = this.AllowPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft;

            RectangleF   pageRect  = e.PageSettings.PrintableArea;
            GraphicsUnit gu        = GraphicsUnit.Pixel;
            RectangleF   imageRect = image.GetBounds(ref gu);

            // rotate the image if it fits the page better
            if (this.AllowPrintRotate)
            {
                if (e.PageSettings.Landscape)
                {
                    if ((pageRect.Width < pageRect.Height && imageRect.Width < imageRect.Height) ||
                        (pageRect.Width > pageRect.Height && imageRect.Width > imageRect.Height))
                    {
                        if (!rotated)
                        {
                            image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                            rotated = true;
                        }
                        else
                        {
                            image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            rotated = false;
                        }
                        imageRect = image.GetBounds(ref gu);
                        if (alignment.Equals(ContentAlignment.TopLeft))
                        {
                            alignment = ContentAlignment.TopRight;
                        }
                    }
                }
                else
                {
                    if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) ||
                        (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height))
                    {
                        if (!rotated)
                        {
                            image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                            rotated = true;
                        }
                        else
                        {
                            image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            rotated = false;
                        }
                        imageRect = image.GetBounds(ref gu);
                        if (alignment.Equals(ContentAlignment.TopLeft))
                        {
                            alignment = ContentAlignment.TopRight;
                        }
                    }
                }
            }
            RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height);;

            // scale the image to fit the page better
            if (this.AllowPrintEnlarge || this.AllowPrintShrink)
            {
                SizeF resizedRect = new SizeF();
                if (e.PageSettings.Landscape)
                {
                    SizeF size = new SizeF(pageRect.Size.Height, pageRect.Size.Width);
                    resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, size, Fill);
                }
                else
                {
                    resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, Fill);
                }

                if ((this.AllowPrintShrink && resizedRect.Width < printRect.Width) ||
                    this.AllowPrintEnlarge && resizedRect.Width > printRect.Width)
                {
                    printRect.Size = resizedRect;
                }
            }
            if (e.PageSettings.Landscape)
            {
                // align the image
                printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Height, pageRect.Width), alignment);
            }
            else
            {
                // align the image
                printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height), alignment);
            }
            e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel);
        }
Esempio n. 39
0
        public override object?ConvertFrom(ITypeDescriptorContext?context, CultureInfo?culture, object value)
        {
            if (!(value is string font))
            {
                return(base.ConvertFrom(context, culture, value));
            }

            font = font.Trim();

            // Expected string format: "name[, size[, units[, style=style1[, style2[...]]]]]"
            // Example using 'vi-VN' culture: "Microsoft Sans Serif, 8,25pt, style=Italic, Bold"
            if (font.Length == 0)
            {
                return(null);
            }

            if (culture == null)
            {
                culture = CultureInfo.CurrentCulture;
            }

            char         separator = culture.TextInfo.ListSeparator[0]; // For vi-VN: ','
            string       fontName  = font;                              // start with the assumption that only the font name was provided.
            string?      style     = null;
            string?      sizeStr;
            float        fontSize  = 8.25f;
            FontStyle    fontStyle = FontStyle.Regular;
            GraphicsUnit units     = GraphicsUnit.Point;

            // Get the index of the first separator (would indicate the end of the name in the string).
            int nameIndex = font.IndexOf(separator);

            if (nameIndex < 0)
            {
                return(new Font(fontName, fontSize, fontStyle, units));
            }

            // Some parameters are provided in addition to name.
            fontName = font.Substring(0, nameIndex);

            if (nameIndex < font.Length - 1)
            {
                // Get the style index (if any). The size is a bit problematic because it can be formatted differently
                // depending on the culture, we'll parse it last.
                int styleIndex = culture.CompareInfo.IndexOf(font, StylePrefix, CompareOptions.IgnoreCase);

                if (styleIndex != -1)
                {
                    // style found.
                    style = font.Substring(styleIndex);

                    // Get the mid-substring containing the size information.
                    sizeStr = font.Substring(nameIndex + 1, styleIndex - nameIndex - 1);
                }
                else
                {
                    // no style.
                    sizeStr = font.Substring(nameIndex + 1);
                }

                // Parse size.
                (string?size, string?unit)unitTokens = ParseSizeTokens(sizeStr, separator);

                if (unitTokens.size != null)
                {
                    try
                    {
                        fontSize = (float)GetFloatConverter().ConvertFromString(context, culture, unitTokens.size) !;
                    }
                    catch
                    {
                        // Exception from converter is too generic.
                        throw new ArgumentException(SR.Format(SR.TextParseFailedFormat, font, $"name{separator} size[units[{separator} style=style1[{separator} style2{separator} ...]]]"), nameof(value));
                    }
                }

                if (unitTokens.unit != null)
                {
                    // ParseGraphicsUnits throws an ArgumentException if format is invalid.
                    units = ParseGraphicsUnits(unitTokens.unit);
                }

                if (style != null)
                {
                    // Parse FontStyle
                    style = style.Substring(6); // style string always starts with style=
                    string[] styleTokens = style.Split(separator);

                    for (int tokenCount = 0; tokenCount < styleTokens.Length; tokenCount++)
                    {
                        string styleText = styleTokens[tokenCount];
                        styleText = styleText.Trim();

                        fontStyle |= Enum.Parse <FontStyle>(styleText, true);

                        // Enum.IsDefined doesn't do what we want on flags enums...
                        FontStyle validBits = FontStyle.Regular | FontStyle.Bold | FontStyle.Italic | FontStyle.Underline | FontStyle.Strikeout;
                        if ((fontStyle | validBits) != validBits)
                        {
                            throw new InvalidEnumArgumentException(nameof(style), (int)fontStyle, typeof(FontStyle));
                        }
                    }
                }
            }

            return(new Font(fontName, fontSize, fontStyle, units));
Esempio n. 40
0
File: GL2.cs Progetto: 894880010/MP
 public void DrawImage(Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit,
                       ImageAttributes imageAttr)
 {
     throw new NotImplementedException();
 }
Esempio n. 41
0
File: GL2.cs Progetto: 894880010/MP
 public void DrawImage(Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr)
 {
     throw new NotImplementedException();
 }
Esempio n. 42
0
File: GL2.cs Progetto: 894880010/MP
 public void DrawImage(Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr,
                       Graphics.DrawImageAbort callback)
 {
     throw new NotImplementedException();
 }
Esempio n. 43
0
        public void generateWallpaper(long monitor, string[] paths)
        {
            // Wallpaper will have exact size of monitors so wallpaper style (Tile, Center, Stretch, Fit, Fill) shouldn't matter
            string       wallpaperPath = Constants.selectProgramAppDataFolder(Constants.WallpaperFileName);
            Rectangle    r             = Constants.getDesktopBounds();
            Bitmap       wallpaper     = new Bitmap(r.Width, r.Height);
            Graphics     g             = Graphics.FromImage(wallpaper);
            GraphicsUnit units         = GraphicsUnit.Pixel;

            if (monitor != Screensaver.CM_ALL)
            {
                if (File.Exists(wallpaperPath))
                {
                    try {
                        Image old = Image.FromFile(wallpaperPath);
                        g.DrawImage(old, old.GetBounds(ref units));
                        old.Dispose();
                    } catch (Exception ex) {
                        this.screensaver.showInfoOnMonitors(ex.Message);
                    }
                }
            }
            Color c = (Color) new ColorConverter().ConvertFromString(Convert.ToString(this.screensaver.config.getPersistant("wallpaperBackgroundColour")));

            System.Drawing.Brush fill = new System.Drawing.SolidBrush(c);

            for (int i = 0; i < Screen.AllScreens.Length; i++)
            {
                if (monitor == Screensaver.CM_ALL || monitor == i)
                {
                    bool  readSuccess = false;
                    Image image       = null;
                    try {
                        image       = Image.FromFile(paths[i]);
                        readSuccess = true;
                    } catch (OutOfMemoryException ex) {
                        this.screensaver.monitors[i].showInfoOnMonitor("Out of memory reading '" + paths[i] + "' for wallpaper");
                    } catch (FileNotFoundException ex) {
                        this.screensaver.monitors[i].showInfoOnMonitor("File not found '" + paths[i] + "' for wallpaper");
                    } catch (System.ArgumentNullException ex) {
                        this.screensaver.monitors[i].showInfoOnMonitor("No file found for wallpaper");
                    }
                    if (readSuccess)
                    {
                        float  imgRatio = (float)image.Width / (float)image.Height;
                        string path     = paths[i];
                        // Panorama
                        Rectangle bounds;
                        Rectangle backgroundBounds;
                        if (i == 0 && this.screensaver.config.getPersistantBool("stretchPanoramas") && imgRatio >= (this.screensaver.desktopRatio * (1 - Convert.ToDouble(this.screensaver.config.getPersistant("stretchPanoramaTolerance")) / 100)))
                        {
                            // ToDo: Stretch wallpaper parts to fit monitor(s)
                            bounds = this.screensaver.Desktop;
                            i      = Screen.AllScreens.Length;
                        }
                        else
                        {
                            bounds = Screen.AllScreens[i].Bounds;
                            if (bounds.X < 0)
                            {
                                bounds.X += r.Width;
                            }
                            if (bounds.Y < 0)
                            {
                                bounds.Y += r.Height;
                            }
                        }

                        g.FillRectangle(fill, bounds);
                        g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                        // Draw faded background image or covered front image
                        if (this.screensaver.config.getPersistantBool("wallpaperBackgroundImage") || this.screensaver.config.getPersistantString("wallpaperFitTo") == "cover")
                        {
                            ColorMatrix colorMatrix = new ColorMatrix();
                            if (this.screensaver.config.getPersistantString("wallpaperFitTo") == "cover")
                            {
                                colorMatrix.Matrix33 = (float)1;
                            }
                            else
                            {
                                colorMatrix.Matrix33 = (float)0.5;
                            }
                            ImageAttributes imageAttributes = new ImageAttributes();
                            imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                            // Get scaled union of screen and image
                            Rectangle source = Constants.FitIntoBounds(bounds, Rectangle.Round(image.GetBounds(ref units)), true, false);
                            Point[]   dest   = { bounds.Location, new Point(bounds.Right, bounds.Top), new Point(bounds.Left, bounds.Bottom) };
                            g.DrawImage(image, dest, source, GraphicsUnit.Pixel, imageAttributes, null);
                        }

                        // Draw font image only if not full cover
                        if (this.screensaver.config.getPersistantString("wallpaperFitTo") != "cover")
                        {
                            g.DrawImage(image, Constants.FitIntoBounds(Rectangle.Round(image.GetBounds(ref units)), bounds, this.screensaver.config.getPersistantBool("wallpaperStretchSmall"), this.screensaver.config.getPersistantString("wallpaperFitTo") == "cover"), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
                        }

                        if (this.screensaver.config.getPersistantBool("wallpaperFilenames"))
                        {
                            // ToDo: Get font settings from config.html
                            Font font = new Font("Arial", 10);
                            g.DrawString(path, font, new SolidBrush(Color.Black), bounds.Left + 1, bounds.Top + 1);
                            g.DrawString(path, font, new SolidBrush(Color.White), bounds.Left, bounds.Top);
                        }
                    }
                }
            }
            if (!Directory.Exists(Path.GetDirectoryName(wallpaperPath)))
            {
                Cursor.Show();
                if (DialogResult.OK != MessageBox.Show("Create folder '" + Path.GetDirectoryName(wallpaperPath) + "'>\n\nOk: Creates folder for backgrounds\nCancel doesn't change background image.", "Installation folder for background not found!", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation))
                {
                    return;
                }
                Cursor.Hide();
                Directory.CreateDirectory(Path.GetDirectoryName(wallpaperPath));
            }
            //try {
            wallpaper.Save(wallpaperPath, System.Drawing.Imaging.ImageFormat.Bmp);
            //} catch(Exception ex) {}

            this.screensaver.config.setPersistant("wallpaperLastChange", Convert.ToString(DateTime.Today));
            Utils.RunTaskScheduler(@"SetWallpaper", Application.ExecutablePath, "/x \"" + wallpaperPath + "\"");
            //Wallpaper.setWallpaper(wallpaperPath);
        }
Esempio n. 44
0
 /// <summary>
 /// Initializes a new instance of the <see cref='Font'/> class with the specified attributes.
 /// </summary>
 public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet)
 {
     Initialize(familyName, emSize, style, unit, gdiCharSet, IsVerticalName(familyName));
 }
Esempio n. 45
0
 public Font(string familyName, float emSize, FontStyle style,
             GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont)
 {
     CreateFont(familyName, emSize, style, unit, gdiCharSet, gdiVerticalFont);
 }
Esempio n. 46
0
 public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit)
     : this(family, emSize, style, unit, DefaultCharSet, false)
 {
 }
Esempio n. 47
0
 public Font(string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet)
     : this(familyName, emSize, style, unit, gdiCharSet, false)
 {
 }
Esempio n. 48
0
File: GL2.cs Progetto: 894880010/MP
 public GraphicsContainer BeginContainer(Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit)
 {
     throw new NotImplementedException();
 }
Esempio n. 49
0
 public Font(string familyName, float emSize, GraphicsUnit unit)
     : this(new FontFamily(familyName), emSize, FontStyle.Regular, unit, DefaultCharSet, false)
 {
 }
Esempio n. 50
0
 /// <summary>
 /// Initializes a new instance of the <see cref='Font'/> class with the specified attributes.
 /// </summary>
 public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont)
 {
     Initialize(family, emSize, style, unit, gdiCharSet, gdiVerticalFont);
 }
Esempio n. 51
0
        internal void setProperties(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical)
        {
            _name       = family.Name;
            _fontFamily = family;
            _size       = emSize;

            // MS throws ArgumentException, if unit is set to GraphicsUnit.Display
            _unit            = unit;
            _style           = style;
            _gdiCharSet      = charSet;
            _gdiVerticalFont = isVertical;

            unitConversion(unit, GraphicsUnit.Point, emSize, out _sizeInPoints);

            _bold = _italic = _strikeout = _underline = false;

            if ((style & FontStyle.Bold) == FontStyle.Bold)
            {
                _bold = true;
            }

            if ((style & FontStyle.Italic) == FontStyle.Italic)
            {
                _italic = true;
            }

            if ((style & FontStyle.Strikeout) == FontStyle.Strikeout)
            {
                _strikeout = true;
            }

            if ((style & FontStyle.Underline) == FontStyle.Underline)
            {
                _underline = true;
            }
        }
Esempio n. 52
0
 /// <summary>
 /// Initializes a new instance of the <see cref='Font'/> class with the specified attributes.
 /// </summary>
 public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte gdiCharSet)
 {
     Initialize(family, emSize, style, unit, gdiCharSet, false);
 }
Esempio n. 53
0
        /// <summary>
        /// Creates the typeface list.
        /// </summary>
        /// <param name="typefaces">The typefaces.</param>
        /// <param name="bold">if set to <c>true</c> [bold].</param>
        /// <param name="italic">if set to <c>true</c> [italic].</param>
        /// <param name="underline">if set to <c>true</c> [underline].</param>
        /// <param name="strikeout">if set to <c>true</c> [strikeout].</param>
        /// <param name="typefaceSize">Size of the typeface.</param>
        /// <param name="graphicsUnit">The graphics unit.</param>
        /// <param name="sampleText">The sample text.</param>
        /// <returns></returns>
        public Bitmap CreateTypefaceList(PrivateFontCollection typefaces, bool bold = false, bool italic = false, bool underline = false, bool strikeout = false, float typefaceSize = 8.25f, GraphicsUnit graphicsUnit = GraphicsUnit.Point, string sampleText = "Lorem Ipsum")
        {
            SolidBrush brush = new SolidBrush(Color.Black);

            float x = 0, y = 0;

            FontStyle style = FontStyle.Regular;

            if (bold)
            {
                style |= FontStyle.Bold;
            }

            if (italic)
            {
                style |= FontStyle.Italic;
            }

            if (underline)
            {
                style |= FontStyle.Underline;
            }

            if (strikeout)
            {
                style |= FontStyle.Strikeout;
            }

            Font normal = new Font("Segoe UI", 12);

            Brush left = new SolidBrush(Color.Brown);

            int width = 0, height = 0, spacing = (int)(1.1 * typefaceSize);

            foreach (var typeface in typefaces.Families)
            {
                try
                {
                    Font newTypeface = new Font(typeface, typefaceSize, style, graphicsUnit);

                    Size size = TextRenderer.MeasureText(sampleText, newTypeface);

                    width = Math.Max(width, size.Width);

                    height += (size.Height > 12 ? size.Height : 12) + spacing;

                    size = TextRenderer.MeasureText(newTypeface.Name, normal);

                    x = Math.Max(x, size.Width + spacing);
                }
                catch (Exception)
                {
                }
            }

            width = (int)(1.2 * width);

            Bitmap bitmap = new Bitmap(width, height);

            using (Graphics gfx = Graphics.FromImage(bitmap))
            {
                gfx.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, width, height));

                foreach (var typeface in typefaces.Families)
                {
                    try
                    {
                        Font newTypeface = new Font(typeface, typefaceSize, style, graphicsUnit);

                        Size size = TextRenderer.MeasureText(sampleText, newTypeface);

                        gfx.DrawString(typeface.Name, normal, left, 0, y);

                        gfx.DrawString(sampleText, newTypeface, brush, x, y);

                        y += size.Height + spacing;
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(bitmap);
        }
Esempio n. 54
0
 /// <summary>
 /// Initializes a new instance of the <see cref='Font'/> class with the specified attributes.
 /// </summary>
 public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit)
 {
     Initialize(family, emSize, style, unit, SafeNativeMethods.DEFAULT_CHARSET, false);
 }
Esempio n. 55
0
 internal static extern int GdipDrawImagePointsRectI(HandleRef graphics, HandleRef image, Point *points, int count, int srcx, int srcy, int srcwidth, int srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort callback, IntPtr callbackdata);
Esempio n. 56
0
 /// <summary>
 /// Initializes a new instance of the <see cref='Font'/> class with the specified attributes.
 /// </summary>
 public Font(string familyName, float emSize, GraphicsUnit unit)
 {
     Initialize(familyName, emSize, FontStyle.Regular, unit, SafeNativeMethods.DEFAULT_CHARSET, IsVerticalName(familyName));
 }
Esempio n. 57
0
 internal static extern int GdipDrawImageRectRectI(HandleRef graphics, HandleRef image, int dstx, int dsty, int dstwidth, int dstheight, int srcx, int srcy, int srcwidth, int srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort callback, IntPtr callbackdata);
 public RectangleF GetBounds(GraphicsUnit& pageUnit)
 {
 }
Esempio n. 59
0
File: GL2.cs Progetto: 894880010/MP
 public void DrawImage(Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight,
                       GraphicsUnit srcUnit)
 {
     throw new NotImplementedException();
 }
Esempio n. 60
0
            public Font GetFont(string fontName, float fontSize, FontStyle fontStyle = FontStyle.Regular, GraphicsUnit graphicsUnit = GraphicsUnit.Point, string defaultFontName = null)
            {
                var args = new CreateFontArgs(fontName, fontSize, fontStyle, graphicsUnit)
                {
                    DefaultFontName = defaultFontName
                };

                return(_gdiObjectFactory.CreateFont(args));
            }