diff options
author | Justin Clark-Casey (justincc) | 2012-08-03 00:00:54 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-08-03 00:00:54 +0100 |
commit | eeef9d7e990cf158de5c143de546fc671169b3bd (patch) | |
tree | 2699280d51378665434c383e3eb993f0b844520c /OpenSim/Region/CoreModules/Scripting | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC_OLD-eeef9d7e990cf158de5c143de546fc671169b3bd.zip opensim-SC_OLD-eeef9d7e990cf158de5c143de546fc671169b3bd.tar.gz opensim-SC_OLD-eeef9d7e990cf158de5c143de546fc671169b3bd.tar.bz2 opensim-SC_OLD-eeef9d7e990cf158de5c143de546fc671169b3bd.tar.xz |
Properly dispose of all GDI+ entities used in VectorRenderModule for dynamic textures.
The convention is that if an object implements IDiposable() the code must explicitly call Dispose() or call it via the using statement.
This may be particularly important for GDI+ objects since they encapsulate native code entities.
Diffstat (limited to 'OpenSim/Region/CoreModules/Scripting')
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs | 569 |
1 files changed, 316 insertions, 253 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs index c061868..d039111 100644 --- a/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/VectorRender/VectorRenderModule.cs | |||
@@ -98,16 +98,18 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender | |||
98 | public void GetDrawStringSize(string text, string fontName, int fontSize, | 98 | public void GetDrawStringSize(string text, string fontName, int fontSize, |
99 | out double xSize, out double ySize) | 99 | out double xSize, out double ySize) |
100 | { | 100 | { |
101 | Font myFont = new Font(fontName, fontSize); | 101 | using (Font myFont = new Font(fontName, fontSize)) |
102 | SizeF stringSize = new SizeF(); | 102 | { |
103 | lock (m_graph) { | 103 | SizeF stringSize = new SizeF(); |
104 | stringSize = m_graph.MeasureString(text, myFont); | 104 | lock (m_graph) |
105 | xSize = stringSize.Width; | 105 | { |
106 | ySize = stringSize.Height; | 106 | stringSize = m_graph.MeasureString(text, myFont); |
107 | xSize = stringSize.Width; | ||
108 | ySize = stringSize.Height; | ||
109 | } | ||
107 | } | 110 | } |
108 | } | 111 | } |
109 | 112 | ||
110 | |||
111 | #endregion | 113 | #endregion |
112 | 114 | ||
113 | #region IRegionModule Members | 115 | #region IRegionModule Members |
@@ -121,6 +123,8 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender | |||
121 | 123 | ||
122 | if (m_graph == null) | 124 | if (m_graph == null) |
123 | { | 125 | { |
126 | // We won't dispose of these explicitly since this module is only removed when the entire simulator | ||
127 | // is shut down. | ||
124 | Bitmap bitmap = new Bitmap(1024, 1024, PixelFormat.Format32bppArgb); | 128 | Bitmap bitmap = new Bitmap(1024, 1024, PixelFormat.Format32bppArgb); |
125 | m_graph = Graphics.FromImage(bitmap); | 129 | m_graph = Graphics.FromImage(bitmap); |
126 | } | 130 | } |
@@ -299,53 +303,64 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender | |||
299 | } | 303 | } |
300 | } | 304 | } |
301 | 305 | ||
302 | Bitmap bitmap; | 306 | Bitmap bitmap = null; |
303 | 307 | Graphics graph = null; | |
304 | if (alpha == 256) | ||
305 | { | ||
306 | bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb); | ||
307 | } | ||
308 | else | ||
309 | { | ||
310 | bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); | ||
311 | } | ||
312 | |||
313 | Graphics graph = Graphics.FromImage(bitmap); | ||
314 | |||
315 | // this is really just to save people filling the | ||
316 | // background color in their scripts, only do when fully opaque | ||
317 | if (alpha >= 255) | ||
318 | { | ||
319 | graph.FillRectangle(new SolidBrush(bgColor), 0, 0, width, height); | ||
320 | } | ||
321 | 308 | ||
322 | for (int w = 0; w < bitmap.Width; w++) | 309 | try |
323 | { | 310 | { |
324 | if (alpha <= 255) | 311 | if (alpha == 256) |
312 | bitmap = new Bitmap(width, height, PixelFormat.Format32bppRgb); | ||
313 | else | ||
314 | bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); | ||
315 | |||
316 | graph = Graphics.FromImage(bitmap); | ||
317 | |||
318 | // this is really just to save people filling the | ||
319 | // background color in their scripts, only do when fully opaque | ||
320 | if (alpha >= 255) | ||
325 | { | 321 | { |
326 | for (int h = 0; h < bitmap.Height; h++) | 322 | using (SolidBrush bgFillBrush = new SolidBrush(bgColor)) |
327 | { | 323 | { |
328 | bitmap.SetPixel(w, h, Color.FromArgb(alpha, bitmap.GetPixel(w, h))); | 324 | graph.FillRectangle(bgFillBrush, 0, 0, width, height); |
329 | } | 325 | } |
330 | } | 326 | } |
331 | } | 327 | |
332 | 328 | for (int w = 0; w < bitmap.Width; w++) | |
333 | GDIDraw(data, graph, altDataDelim); | 329 | { |
334 | 330 | if (alpha <= 255) | |
335 | byte[] imageJ2000 = new byte[0]; | 331 | { |
332 | for (int h = 0; h < bitmap.Height; h++) | ||
333 | { | ||
334 | bitmap.SetPixel(w, h, Color.FromArgb(alpha, bitmap.GetPixel(w, h))); | ||
335 | } | ||
336 | } | ||
337 | } | ||
338 | |||
339 | GDIDraw(data, graph, altDataDelim); | ||
340 | |||
341 | byte[] imageJ2000 = new byte[0]; | ||
342 | |||
343 | try | ||
344 | { | ||
345 | imageJ2000 = OpenJPEG.EncodeFromImage(bitmap, true); | ||
346 | } | ||
347 | catch (Exception e) | ||
348 | { | ||
349 | m_log.ErrorFormat( | ||
350 | "[VECTORRENDERMODULE]: OpenJpeg Encode Failed. Exception {0}{1}", | ||
351 | e.Message, e.StackTrace); | ||
352 | } | ||
336 | 353 | ||
337 | try | 354 | m_textureManager.ReturnData(id, imageJ2000); |
338 | { | ||
339 | imageJ2000 = OpenJPEG.EncodeFromImage(bitmap, true); | ||
340 | } | 355 | } |
341 | catch (Exception e) | 356 | finally |
342 | { | 357 | { |
343 | m_log.ErrorFormat( | 358 | if (graph != null) |
344 | "[VECTORRENDERMODULE]: OpenJpeg Encode Failed. Exception {0}{1}", | 359 | graph.Dispose(); |
345 | e.Message, e.StackTrace); | ||
346 | } | ||
347 | 360 | ||
348 | m_textureManager.ReturnData(id, imageJ2000); | 361 | if (bitmap != null) |
362 | bitmap.Dispose(); | ||
363 | } | ||
349 | } | 364 | } |
350 | 365 | ||
351 | private int parseIntParam(string strInt) | 366 | private int parseIntParam(string strInt) |
@@ -407,238 +422,285 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender | |||
407 | { | 422 | { |
408 | Point startPoint = new Point(0, 0); | 423 | Point startPoint = new Point(0, 0); |
409 | Point endPoint = new Point(0, 0); | 424 | Point endPoint = new Point(0, 0); |
410 | Pen drawPen = new Pen(Color.Black, 7); | 425 | Pen drawPen = null; |
411 | string fontName = m_fontName; | 426 | Font myFont = null; |
412 | float fontSize = 14; | 427 | SolidBrush myBrush = null; |
413 | Font myFont = new Font(fontName, fontSize); | ||
414 | SolidBrush myBrush = new SolidBrush(Color.Black); | ||
415 | |||
416 | char[] lineDelimiter = {dataDelim}; | ||
417 | char[] partsDelimiter = {','}; | ||
418 | string[] lines = data.Split(lineDelimiter); | ||
419 | 428 | ||
420 | foreach (string line in lines) | 429 | try |
421 | { | 430 | { |
422 | string nextLine = line.Trim(); | 431 | drawPen = new Pen(Color.Black, 7); |
423 | //replace with switch, or even better, do some proper parsing | 432 | string fontName = m_fontName; |
424 | if (nextLine.StartsWith("MoveTo")) | 433 | float fontSize = 14; |
425 | { | 434 | myFont = new Font(fontName, fontSize); |
426 | float x = 0; | 435 | myBrush = new SolidBrush(Color.Black); |
427 | float y = 0; | 436 | |
428 | GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y); | 437 | char[] lineDelimiter = {dataDelim}; |
429 | startPoint.X = (int) x; | 438 | char[] partsDelimiter = {','}; |
430 | startPoint.Y = (int) y; | 439 | string[] lines = data.Split(lineDelimiter); |
431 | } | 440 | |
432 | else if (nextLine.StartsWith("LineTo")) | 441 | foreach (string line in lines) |
433 | { | ||
434 | float x = 0; | ||
435 | float y = 0; | ||
436 | GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y); | ||
437 | endPoint.X = (int) x; | ||
438 | endPoint.Y = (int) y; | ||
439 | graph.DrawLine(drawPen, startPoint, endPoint); | ||
440 | startPoint.X = endPoint.X; | ||
441 | startPoint.Y = endPoint.Y; | ||
442 | } | ||
443 | else if (nextLine.StartsWith("Text")) | ||
444 | { | ||
445 | nextLine = nextLine.Remove(0, 4); | ||
446 | nextLine = nextLine.Trim(); | ||
447 | graph.DrawString(nextLine, myFont, myBrush, startPoint); | ||
448 | } | ||
449 | else if (nextLine.StartsWith("Image")) | ||
450 | { | 442 | { |
451 | float x = 0; | 443 | string nextLine = line.Trim(); |
452 | float y = 0; | 444 | //replace with switch, or even better, do some proper parsing |
453 | GetParams(partsDelimiter, ref nextLine, 5, ref x, ref y); | 445 | if (nextLine.StartsWith("MoveTo")) |
454 | endPoint.X = (int) x; | ||
455 | endPoint.Y = (int) y; | ||
456 | Image image = ImageHttpRequest(nextLine); | ||
457 | if (image != null) | ||
458 | { | 446 | { |
459 | graph.DrawImage(image, (float)startPoint.X, (float)startPoint.Y, x, y); | 447 | float x = 0; |
448 | float y = 0; | ||
449 | GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y); | ||
450 | startPoint.X = (int) x; | ||
451 | startPoint.Y = (int) y; | ||
460 | } | 452 | } |
461 | else | 453 | else if (nextLine.StartsWith("LineTo")) |
462 | { | 454 | { |
463 | graph.DrawString("URL couldn't be resolved or is", new Font(m_fontName,6), | 455 | float x = 0; |
464 | myBrush, startPoint); | 456 | float y = 0; |
465 | graph.DrawString("not an image. Please check URL.", new Font(m_fontName, 6), | 457 | GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y); |
466 | myBrush, new Point(startPoint.X, 12 + startPoint.Y)); | 458 | endPoint.X = (int) x; |
467 | graph.DrawRectangle(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | 459 | endPoint.Y = (int) y; |
460 | graph.DrawLine(drawPen, startPoint, endPoint); | ||
461 | startPoint.X = endPoint.X; | ||
462 | startPoint.Y = endPoint.Y; | ||
468 | } | 463 | } |
469 | startPoint.X += endPoint.X; | 464 | else if (nextLine.StartsWith("Text")) |
470 | startPoint.Y += endPoint.Y; | 465 | { |
471 | } | 466 | nextLine = nextLine.Remove(0, 4); |
472 | else if (nextLine.StartsWith("Rectangle")) | 467 | nextLine = nextLine.Trim(); |
473 | { | 468 | graph.DrawString(nextLine, myFont, myBrush, startPoint); |
474 | float x = 0; | 469 | } |
475 | float y = 0; | 470 | else if (nextLine.StartsWith("Image")) |
476 | GetParams(partsDelimiter, ref nextLine, 9, ref x, ref y); | ||
477 | endPoint.X = (int) x; | ||
478 | endPoint.Y = (int) y; | ||
479 | graph.DrawRectangle(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
480 | startPoint.X += endPoint.X; | ||
481 | startPoint.Y += endPoint.Y; | ||
482 | } | ||
483 | else if (nextLine.StartsWith("FillRectangle")) | ||
484 | { | ||
485 | float x = 0; | ||
486 | float y = 0; | ||
487 | GetParams(partsDelimiter, ref nextLine, 13, ref x, ref y); | ||
488 | endPoint.X = (int) x; | ||
489 | endPoint.Y = (int) y; | ||
490 | graph.FillRectangle(myBrush, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
491 | startPoint.X += endPoint.X; | ||
492 | startPoint.Y += endPoint.Y; | ||
493 | } | ||
494 | else if (nextLine.StartsWith("FillPolygon")) | ||
495 | { | ||
496 | PointF[] points = null; | ||
497 | GetParams(partsDelimiter, ref nextLine, 11, ref points); | ||
498 | graph.FillPolygon(myBrush, points); | ||
499 | } | ||
500 | else if (nextLine.StartsWith("Polygon")) | ||
501 | { | ||
502 | PointF[] points = null; | ||
503 | GetParams(partsDelimiter, ref nextLine, 7, ref points); | ||
504 | graph.DrawPolygon(drawPen, points); | ||
505 | } | ||
506 | else if (nextLine.StartsWith("Ellipse")) | ||
507 | { | ||
508 | float x = 0; | ||
509 | float y = 0; | ||
510 | GetParams(partsDelimiter, ref nextLine, 7, ref x, ref y); | ||
511 | endPoint.X = (int)x; | ||
512 | endPoint.Y = (int)y; | ||
513 | graph.DrawEllipse(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
514 | startPoint.X += endPoint.X; | ||
515 | startPoint.Y += endPoint.Y; | ||
516 | } | ||
517 | else if (nextLine.StartsWith("FontSize")) | ||
518 | { | ||
519 | nextLine = nextLine.Remove(0, 8); | ||
520 | nextLine = nextLine.Trim(); | ||
521 | fontSize = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture); | ||
522 | myFont = new Font(fontName, fontSize); | ||
523 | } | ||
524 | else if (nextLine.StartsWith("FontProp")) | ||
525 | { | ||
526 | nextLine = nextLine.Remove(0, 8); | ||
527 | nextLine = nextLine.Trim(); | ||
528 | |||
529 | string[] fprops = nextLine.Split(partsDelimiter); | ||
530 | foreach (string prop in fprops) | ||
531 | { | 471 | { |
472 | float x = 0; | ||
473 | float y = 0; | ||
474 | GetParams(partsDelimiter, ref nextLine, 5, ref x, ref y); | ||
475 | endPoint.X = (int) x; | ||
476 | endPoint.Y = (int) y; | ||
532 | 477 | ||
533 | switch (prop) | 478 | using (Image image = ImageHttpRequest(nextLine)) |
534 | { | 479 | { |
535 | case "B": | 480 | if (image != null) |
536 | if (!(myFont.Bold)) | 481 | { |
537 | myFont = new Font(myFont, myFont.Style | FontStyle.Bold); | 482 | graph.DrawImage(image, (float)startPoint.X, (float)startPoint.Y, x, y); |
538 | break; | 483 | } |
539 | case "I": | 484 | else |
540 | if (!(myFont.Italic)) | 485 | { |
541 | myFont = new Font(myFont, myFont.Style | FontStyle.Italic); | 486 | using (Font errorFont = new Font(m_fontName,6)) |
542 | break; | 487 | { |
543 | case "U": | 488 | graph.DrawString("URL couldn't be resolved or is", errorFont, |
544 | if (!(myFont.Underline)) | 489 | myBrush, startPoint); |
545 | myFont = new Font(myFont, myFont.Style | FontStyle.Underline); | 490 | graph.DrawString("not an image. Please check URL.", errorFont, |
546 | break; | 491 | myBrush, new Point(startPoint.X, 12 + startPoint.Y)); |
547 | case "S": | 492 | } |
548 | if (!(myFont.Strikeout)) | 493 | |
549 | myFont = new Font(myFont, myFont.Style | FontStyle.Strikeout); | 494 | graph.DrawRectangle(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); |
550 | break; | 495 | } |
551 | case "R": | ||
552 | myFont = new Font(myFont, FontStyle.Regular); | ||
553 | break; | ||
554 | } | 496 | } |
497 | |||
498 | startPoint.X += endPoint.X; | ||
499 | startPoint.Y += endPoint.Y; | ||
555 | } | 500 | } |
556 | } | 501 | else if (nextLine.StartsWith("Rectangle")) |
557 | else if (nextLine.StartsWith("FontName")) | ||
558 | { | ||
559 | nextLine = nextLine.Remove(0, 8); | ||
560 | fontName = nextLine.Trim(); | ||
561 | myFont = new Font(fontName, fontSize); | ||
562 | } | ||
563 | else if (nextLine.StartsWith("PenSize")) | ||
564 | { | ||
565 | nextLine = nextLine.Remove(0, 7); | ||
566 | nextLine = nextLine.Trim(); | ||
567 | float size = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture); | ||
568 | drawPen.Width = size; | ||
569 | } | ||
570 | else if (nextLine.StartsWith("PenCap")) | ||
571 | { | ||
572 | bool start = true, end = true; | ||
573 | nextLine = nextLine.Remove(0, 6); | ||
574 | nextLine = nextLine.Trim(); | ||
575 | string[] cap = nextLine.Split(partsDelimiter); | ||
576 | if (cap[0].ToLower() == "start") | ||
577 | end = false; | ||
578 | else if (cap[0].ToLower() == "end") | ||
579 | start = false; | ||
580 | else if (cap[0].ToLower() != "both") | ||
581 | return; | ||
582 | string type = cap[1].ToLower(); | ||
583 | |||
584 | if (end) | ||
585 | { | 502 | { |
586 | switch (type) | 503 | float x = 0; |
587 | { | 504 | float y = 0; |
588 | case "arrow": | 505 | GetParams(partsDelimiter, ref nextLine, 9, ref x, ref y); |
589 | drawPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; | 506 | endPoint.X = (int) x; |
590 | break; | 507 | endPoint.Y = (int) y; |
591 | case "round": | 508 | graph.DrawRectangle(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); |
592 | drawPen.EndCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; | 509 | startPoint.X += endPoint.X; |
593 | break; | 510 | startPoint.Y += endPoint.Y; |
594 | case "diamond": | 511 | } |
595 | drawPen.EndCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; | 512 | else if (nextLine.StartsWith("FillRectangle")) |
596 | break; | 513 | { |
597 | case "flat": | 514 | float x = 0; |
598 | drawPen.EndCap = System.Drawing.Drawing2D.LineCap.Flat; | 515 | float y = 0; |
599 | break; | 516 | GetParams(partsDelimiter, ref nextLine, 13, ref x, ref y); |
600 | } | 517 | endPoint.X = (int) x; |
518 | endPoint.Y = (int) y; | ||
519 | graph.FillRectangle(myBrush, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
520 | startPoint.X += endPoint.X; | ||
521 | startPoint.Y += endPoint.Y; | ||
522 | } | ||
523 | else if (nextLine.StartsWith("FillPolygon")) | ||
524 | { | ||
525 | PointF[] points = null; | ||
526 | GetParams(partsDelimiter, ref nextLine, 11, ref points); | ||
527 | graph.FillPolygon(myBrush, points); | ||
601 | } | 528 | } |
602 | if (start) | 529 | else if (nextLine.StartsWith("Polygon")) |
603 | { | 530 | { |
604 | switch (type) | 531 | PointF[] points = null; |
532 | GetParams(partsDelimiter, ref nextLine, 7, ref points); | ||
533 | graph.DrawPolygon(drawPen, points); | ||
534 | } | ||
535 | else if (nextLine.StartsWith("Ellipse")) | ||
536 | { | ||
537 | float x = 0; | ||
538 | float y = 0; | ||
539 | GetParams(partsDelimiter, ref nextLine, 7, ref x, ref y); | ||
540 | endPoint.X = (int)x; | ||
541 | endPoint.Y = (int)y; | ||
542 | graph.DrawEllipse(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); | ||
543 | startPoint.X += endPoint.X; | ||
544 | startPoint.Y += endPoint.Y; | ||
545 | } | ||
546 | else if (nextLine.StartsWith("FontSize")) | ||
547 | { | ||
548 | nextLine = nextLine.Remove(0, 8); | ||
549 | nextLine = nextLine.Trim(); | ||
550 | fontSize = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture); | ||
551 | |||
552 | myFont.Dispose(); | ||
553 | myFont = new Font(fontName, fontSize); | ||
554 | } | ||
555 | else if (nextLine.StartsWith("FontProp")) | ||
556 | { | ||
557 | nextLine = nextLine.Remove(0, 8); | ||
558 | nextLine = nextLine.Trim(); | ||
559 | |||
560 | string[] fprops = nextLine.Split(partsDelimiter); | ||
561 | foreach (string prop in fprops) | ||
605 | { | 562 | { |
606 | case "arrow": | 563 | |
607 | drawPen.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; | 564 | switch (prop) |
608 | break; | 565 | { |
609 | case "round": | 566 | case "B": |
610 | drawPen.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; | 567 | if (!(myFont.Bold)) |
611 | break; | 568 | { |
612 | case "diamond": | 569 | Font newFont = new Font(myFont, myFont.Style | FontStyle.Bold); |
613 | drawPen.StartCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; | 570 | myFont.Dispose(); |
614 | break; | 571 | myFont = newFont; |
615 | case "flat": | 572 | } |
616 | drawPen.StartCap = System.Drawing.Drawing2D.LineCap.Flat; | 573 | break; |
617 | break; | 574 | case "I": |
575 | if (!(myFont.Italic)) | ||
576 | { | ||
577 | Font newFont = new Font(myFont, myFont.Style | FontStyle.Italic); | ||
578 | myFont.Dispose(); | ||
579 | myFont = newFont; | ||
580 | } | ||
581 | break; | ||
582 | case "U": | ||
583 | if (!(myFont.Underline)) | ||
584 | { | ||
585 | Font newFont = new Font(myFont, myFont.Style | FontStyle.Underline); | ||
586 | myFont.Dispose(); | ||
587 | myFont = newFont; | ||
588 | } | ||
589 | break; | ||
590 | case "S": | ||
591 | if (!(myFont.Strikeout)) | ||
592 | { | ||
593 | Font newFont = new Font(myFont, myFont.Style | FontStyle.Strikeout); | ||
594 | myFont.Dispose(); | ||
595 | myFont = newFont; | ||
596 | } | ||
597 | break; | ||
598 | case "R": | ||
599 | Font newFont = new Font(myFont, FontStyle.Regular); | ||
600 | myFont.Dispose(); | ||
601 | myFont = newFont; | ||
602 | break; | ||
603 | } | ||
618 | } | 604 | } |
619 | } | 605 | } |
620 | } | 606 | else if (nextLine.StartsWith("FontName")) |
621 | else if (nextLine.StartsWith("PenColour") || nextLine.StartsWith("PenColor")) | ||
622 | { | ||
623 | nextLine = nextLine.Remove(0, 9); | ||
624 | nextLine = nextLine.Trim(); | ||
625 | int hex = 0; | ||
626 | |||
627 | Color newColor; | ||
628 | if (Int32.TryParse(nextLine, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex)) | ||
629 | { | 607 | { |
630 | newColor = Color.FromArgb(hex); | 608 | nextLine = nextLine.Remove(0, 8); |
609 | fontName = nextLine.Trim(); | ||
610 | myFont.Dispose(); | ||
611 | myFont = new Font(fontName, fontSize); | ||
631 | } | 612 | } |
632 | else | 613 | else if (nextLine.StartsWith("PenSize")) |
633 | { | 614 | { |
634 | // this doesn't fail, it just returns black if nothing is found | 615 | nextLine = nextLine.Remove(0, 7); |
635 | newColor = Color.FromName(nextLine); | 616 | nextLine = nextLine.Trim(); |
617 | float size = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture); | ||
618 | drawPen.Width = size; | ||
636 | } | 619 | } |
620 | else if (nextLine.StartsWith("PenCap")) | ||
621 | { | ||
622 | bool start = true, end = true; | ||
623 | nextLine = nextLine.Remove(0, 6); | ||
624 | nextLine = nextLine.Trim(); | ||
625 | string[] cap = nextLine.Split(partsDelimiter); | ||
626 | if (cap[0].ToLower() == "start") | ||
627 | end = false; | ||
628 | else if (cap[0].ToLower() == "end") | ||
629 | start = false; | ||
630 | else if (cap[0].ToLower() != "both") | ||
631 | return; | ||
632 | string type = cap[1].ToLower(); | ||
633 | |||
634 | if (end) | ||
635 | { | ||
636 | switch (type) | ||
637 | { | ||
638 | case "arrow": | ||
639 | drawPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; | ||
640 | break; | ||
641 | case "round": | ||
642 | drawPen.EndCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; | ||
643 | break; | ||
644 | case "diamond": | ||
645 | drawPen.EndCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; | ||
646 | break; | ||
647 | case "flat": | ||
648 | drawPen.EndCap = System.Drawing.Drawing2D.LineCap.Flat; | ||
649 | break; | ||
650 | } | ||
651 | } | ||
652 | if (start) | ||
653 | { | ||
654 | switch (type) | ||
655 | { | ||
656 | case "arrow": | ||
657 | drawPen.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; | ||
658 | break; | ||
659 | case "round": | ||
660 | drawPen.StartCap = System.Drawing.Drawing2D.LineCap.RoundAnchor; | ||
661 | break; | ||
662 | case "diamond": | ||
663 | drawPen.StartCap = System.Drawing.Drawing2D.LineCap.DiamondAnchor; | ||
664 | break; | ||
665 | case "flat": | ||
666 | drawPen.StartCap = System.Drawing.Drawing2D.LineCap.Flat; | ||
667 | break; | ||
668 | } | ||
669 | } | ||
670 | } | ||
671 | else if (nextLine.StartsWith("PenColour") || nextLine.StartsWith("PenColor")) | ||
672 | { | ||
673 | nextLine = nextLine.Remove(0, 9); | ||
674 | nextLine = nextLine.Trim(); | ||
675 | int hex = 0; | ||
676 | |||
677 | Color newColor; | ||
678 | if (Int32.TryParse(nextLine, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex)) | ||
679 | { | ||
680 | newColor = Color.FromArgb(hex); | ||
681 | } | ||
682 | else | ||
683 | { | ||
684 | // this doesn't fail, it just returns black if nothing is found | ||
685 | newColor = Color.FromName(nextLine); | ||
686 | } | ||
637 | 687 | ||
638 | myBrush.Color = newColor; | 688 | myBrush.Color = newColor; |
639 | drawPen.Color = newColor; | 689 | drawPen.Color = newColor; |
690 | } | ||
640 | } | 691 | } |
641 | } | 692 | } |
693 | finally | ||
694 | { | ||
695 | if (drawPen != null) | ||
696 | drawPen.Dispose(); | ||
697 | |||
698 | if (myFont != null) | ||
699 | myFont.Dispose(); | ||
700 | |||
701 | if (myBrush != null) | ||
702 | myBrush.Dispose(); | ||
703 | } | ||
642 | } | 704 | } |
643 | 705 | ||
644 | private static void GetParams(char[] partsDelimiter, ref string line, int startLength, ref float x, ref float y) | 706 | private static void GetParams(char[] partsDelimiter, ref string line, int startLength, ref float x, ref float y) |
@@ -691,7 +753,7 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender | |||
691 | { | 753 | { |
692 | try | 754 | try |
693 | { | 755 | { |
694 | WebRequest request = HttpWebRequest.Create(url); | 756 | WebRequest request = HttpWebRequest.Create(url); |
695 | //Ckrinke: Comment out for now as 'str' is unused. Bring it back into play later when it is used. | 757 | //Ckrinke: Comment out for now as 'str' is unused. Bring it back into play later when it is used. |
696 | //Ckrinke Stream str = null; | 758 | //Ckrinke Stream str = null; |
697 | HttpWebResponse response = (HttpWebResponse)(request).GetResponse(); | 759 | HttpWebResponse response = (HttpWebResponse)(request).GetResponse(); |
@@ -702,7 +764,8 @@ namespace OpenSim.Region.CoreModules.Scripting.VectorRender | |||
702 | } | 764 | } |
703 | } | 765 | } |
704 | catch { } | 766 | catch { } |
767 | |||
705 | return null; | 768 | return null; |
706 | } | 769 | } |
707 | } | 770 | } |
708 | } | 771 | } \ No newline at end of file |