Search Results

Search found 5 results on 1 pages for 'privatefontcollection'.

Page 1/1 | 1 

  • Workaround for the Mono PrivateFontCollection.AddFontFile bug

    - by CommuSoft
    When I call the PrivateFontCollection.AddFontFile method in Mono.net It always returns a standard font-family. This bug has already been reported on several websites, but as far as I know without a way to solve it. The bug itself isn't fixed in the Mono-libraries yet. Is there any workaround for it? EDIT: As a reaction on henchman's answer I will post the code: PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile("myFontFamily.ttf"); myFontFamily = pfc.Families[0x00]; Font myFont = new Font(myFontFamily,14.0f); I know this code will work fine on the Microsoft.Net framework, but when executing on Mono, it just gives a standard font-family (I think it is Arial) with the name of myFontFamily.ttf

    Read the article

  • PrivateFontCollection fails on appharbor

    - by grennis
    I am trying to load a custom font (ttf file) and draw into an image with the Graphics object. This code runs fine locally: PrivateFontCollection fonts = new PrivateFontCollection(); string path = context.Server.MapPath("~/App_Data/Futura LT Bold.ttf"); if (!System.IO.File.Exists(path)) { throw new InvalidOperationException("Font file is not deployed: " + path); } fonts.AddFontFile(path); However when run on appharbor, the call to AddFontFile fails with the exception: System.ArgumentException: Font 'Futura LT Book' does not support style 'Regular'. at System.Drawing.Font.CreateNativeFont() at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont) at System.Drawing.Font..ctor(FontFamily family, Single emSize) at LumenboxWeb.Controllers.GalleryController.FontTest() in d:\temp\h5oqslma.udd\input\src\LumenboxWeb\Controllers\GalleryController.cs:line 59 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) I have tried different fonts, and they all work locally, but none work on appharbor. Is it possible to load fonts dynamically on appharbor?

    Read the article

  • Why are my installed fonts not available in .NET?

    - by Dan Herbert
    I'm trying to render some images with text using a font I just added to my machine and no matter what I do, I can't seem to get the font to become accessible in .NET. I tried using PrivateFontCollection.AddFontFile(filename) and PrivateFontCollection.AddMemoryFont(...) to load the font into memory. Whenever I do this, the method throws a "File Not Found" exception, which is unusual because I get this exception when loading the font from memory, where there should be no files to be "not found". Initially, I thought it may be because the font I was trying to use was in the .pfm format, so I converted the font to .otf and had the same problem. Then I tried installing the .otf font to my Windows Fonts folder so I could pull it from FontFamily.Families. Once I installed the font, it became available in Microsoft Word & Notepad2. However, when I try to load it from FontFamily.Families, it is not included in the array. I thought rebooting my machine would fix the issue but obviously there is something more complicated involved here. Is there something basic I just might have missed when installing the font in my machine (Windows Vista), or is there another way to programmatically load a font that I should be using instead? Is .otf not supported in .NET?

    Read the article

  • How to adjust size of programatically created Bitmap to match text drawn on it?

    - by TooFat
    I have the following .ashx page that takes some query string parameters and returns a bitmap with the specified text written on it. The problem I have is that I am currently just manually setting the initial size of the bitmap at 100 X 100 when what I really want is to have the bitmap be just big enough to include all the text that was written to it. How can I do this? public void ProcessRequest (HttpContext context) { context.Response.ContentType = "image/png"; string text = context.Request.QueryString["Text"]; //set FontName string fontName; if (context.Request.QueryString["FontName"] != null) { fontName = context.Request.QueryString["FontName"]; } else { fontName = "Arial"; } //Set FontSize int fontEms; if (context.Request.QueryString["FontSize"] != null) { string fontSize = context.Request.QueryString["FontSize"]; fontEms = Int32.Parse(fontSize); } else { fontEms = 12; } //Set Font Color System.Drawing.Color color; if (context.Request.QueryString["FontColor"] != null) { string fontColor = context.Request.QueryString["FontColor"]; color = System.Drawing.ColorTranslator.FromHtml(fontColor); context.Response.Write(color.ToString()); } else { color = System.Drawing.Color.Red; } using (System.Drawing.Text.PrivateFontCollection fnts = new System.Drawing.Text.PrivateFontCollection()) using (System.Drawing.FontFamily fntfam = new System.Drawing.FontFamily(fontName)) using (System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(color)) using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(100, 100)) { using (System.Drawing.Font fnt = new System.Drawing.Font(fntfam, fontEms)) { fnts.AddFontFile(System.IO.Path.Combine(@"C:\Development\Fonts\", fontName)); System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(bmp); graph.DrawString(text, fnt, brush, new System.Drawing.Point(0, 0)); string imgPath = System.IO.Path.Combine(@"C:\Development\MyPath\Images\Text", System.IO.Path.GetRandomFileName()); bmp.Save(imgPath); context.Response.WriteFile(imgPath); } } }

    Read the article

  • Graphics.MeasureCharacterRanges giving wrong size calculations in C#.Net?

    - by Owen Blacker
    I'm trying to render some text into a specific part of an image in a Web Forms app. The text will be user entered, so I want to vary the font size to make sure it fits within the bounding box. I have code that was doing this fine on my proof-of-concept implementation, but I'm now trying it against the assets from the designer, which are larger, and I'm getting some odd results. I'm running the size calculation as follows: StringFormat fmt = new StringFormat(); fmt.Alignment = StringAlignment.Center; fmt.LineAlignment = StringAlignment.Near; fmt.FormatFlags = StringFormatFlags.NoClip; fmt.Trimming = StringTrimming.None; int size = __startingSize; Font font = __fonts.GetFontBySize(size); while (GetStringBounds(text, font, fmt).IsLargerThan(__textBoundingBox)) { context.Trace.Write("MyHandler.ProcessRequest", "Decrementing font size to " + size + ", as size is " + GetStringBounds(text, font, fmt).Size() + " and limit is " + __textBoundingBox.Size()); size--; if (size < __minimumSize) { break; } font = __fonts.GetFontBySize(size); } context.Trace.Write("MyHandler.ProcessRequest", "Writing " + text + " in " + font.FontFamily.Name + " at " + font.SizeInPoints + "pt, size is " + GetStringBounds(text, font, fmt).Size() + " and limit is " + __textBoundingBox.Size()); I then use the following line to render the text onto an image I'm pulling from the filesystem: g.DrawString(text, font, __brush, __textBoundingBox, fmt); where: __fonts is a PrivateFontCollection, PrivateFontCollection.GetFontBySize is an extension method that returns a FontFamily RectangleF __textBoundingBox = new RectangleF(150, 110, 212, 64); int __minimumSize = 8; int __startingSize = 48; Brush __brush = Brushes.White; int size starts out at 48 and decrements within that loop Graphics g has SmoothingMode.AntiAlias and TextRenderingHint.AntiAlias set context is a System.Web.HttpContext (this is an excerpt from the ProcessRequest method of an IHttpHandler) The other methods are: private static RectangleF GetStringBounds(string text, Font font, StringFormat fmt) { CharacterRange[] range = { new CharacterRange(0, text.Length) }; StringFormat myFormat = fmt.Clone() as StringFormat; myFormat.SetMeasurableCharacterRanges(range); using (Graphics g = Graphics.FromImage(new Bitmap( (int) __textBoundingBox.Width - 1, (int) __textBoundingBox.Height - 1))) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; Region[] regions = g.MeasureCharacterRanges(text, font, __textBoundingBox, myFormat); return regions[0].GetBounds(g); } } public static string Size(this RectangleF rect) { return rect.Width + "×" + rect.Height; } public static bool IsLargerThan(this RectangleF a, RectangleF b) { return (a.Width > b.Width) || (a.Height > b.Height); } Now I have two problems. Firstly, the text sometimes insists on wrapping by inserting a line-break within a word, when it should just fail to fit and cause the while loop to decrement again. I can't see why it is that Graphics.MeasureCharacterRanges thinks that this fits within the box when it shouldn't be word-wrapping within a word. This behaviour is exhibited irrespective of the character set used (I get it in Latin alphabet words, as well as other parts of the Unicode range, like Cyrillic, Greek, Georgian and Armenian). Is there some setting I should be using to force Graphics.MeasureCharacterRanges only to be word-wrapping at whitespace characters (or hyphens)? This first problem is the same as post 2499067. Secondly, in scaling up to the new image and font size, Graphics.MeasureCharacterRanges is giving me heights that are wildly off. The RectangleF I am drawing within corresponds to a visually apparent area of the image, so I can easily see when the text is being decremented more than is necessary. Yet when I pass it some text, the GetBounds call is giving me a height that is almost double what it's actually taking. Using trial and error to set the __minimumSize to force an exit from the while loop, I can see that 24pt text fits within the bounding box, yet Graphics.MeasureCharacterRanges is reporting that the height of that text, once rendered to the image, is 122px (when the bounding box is 64px tall and it fits within that box). Indeed, without forcing the matter, the while loop iterates to 18pt, at which point Graphics.MeasureCharacterRanges returns a value that fits. The trace log excerpt is as follows: Decrementing font size to 24, as size is 193×122 and limit is 212×64 Decrementing font size to 23, as size is 191×117 and limit is 212×64 Decrementing font size to 22, as size is 200×75 and limit is 212×64 Decrementing font size to 21, as size is 192×71 and limit is 212×64 Decrementing font size to 20, as size is 198×68 and limit is 212×64 Decrementing font size to 19, as size is 185×65 and limit is 212×64 Writing VENNEGOOR of HESSELINK in DIN-Black at 18pt, size is 178×61 and limit is 212×64 So why is Graphics.MeasureCharacterRanges giving me a wrong result? I could understand it being, say, the line height of the font if the loop stopped around 21pt (which would visually fit, if I screenshot the results and measure it in Paint.Net), but it's going far further than it should be doing because, frankly, it's returning the wrong damn results. Any and all help gratefully received. Thanks!

    Read the article

1