Graphics.jvm.cs 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564
  1. using System;
  2. using System.Drawing.Drawing2D;
  3. using System.Drawing.Imaging;
  4. using System.Drawing.Text;
  5. using System.ComponentModel;
  6. using System.Collections;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using awt = java.awt;
  10. using geom = java.awt.geom;
  11. namespace System.Drawing {
  12. [ComVisible(false)]
  13. public sealed class Graphics : MarshalByRefObject, IDisposable {
  14. sealed class DummyStroke : awt.Stroke {
  15. #region Stroke Members
  16. awt.Shape awt.Stroke.createStrokedShape(awt.Shape arg_0) {
  17. throw new NotImplementedException("DummyStroke");
  18. }
  19. #endregion
  20. }
  21. sealed class NormalizingPathIterator : geom.PathIterator {
  22. #region fields
  23. readonly geom.PathIterator _iter;
  24. const float norm = 0.5f;
  25. const float rnd = (1.0f - norm);
  26. float ax = 0.0f;
  27. float ay = 0.0f;
  28. #endregion
  29. #region ctor
  30. public NormalizingPathIterator(geom.PathIterator iter) {
  31. _iter = iter;
  32. }
  33. #endregion
  34. #region methods
  35. static int GetIndex(int type) {
  36. int index;
  37. switch ((GraphicsPath.JPI)type) {
  38. case GraphicsPath.JPI.SEG_CUBICTO:
  39. index = 4;
  40. break;
  41. case GraphicsPath.JPI.SEG_QUADTO:
  42. index = 2;
  43. break;
  44. case GraphicsPath.JPI.SEG_MOVETO:
  45. case GraphicsPath.JPI.SEG_LINETO:
  46. index = 0;
  47. break;
  48. case GraphicsPath.JPI.SEG_CLOSE:
  49. default:
  50. index = -1;
  51. break;
  52. }
  53. return index;
  54. }
  55. #endregion
  56. #region PathIterator Members
  57. void geom.PathIterator.next() {
  58. _iter.next();
  59. }
  60. bool geom.PathIterator.isDone() {
  61. return _iter.isDone();
  62. }
  63. int geom.PathIterator.currentSegment(float[] point) {
  64. int type = _iter.currentSegment(point);
  65. int index = GetIndex(type);
  66. if (index >= 0) {
  67. float ox = point[index];
  68. float oy = point[index+1];
  69. float newax = (float) java.lang.Math.floor(ox + rnd) + norm;
  70. float neway = (float) java.lang.Math.floor(oy + rnd) + norm;
  71. point[index] = newax;
  72. point[index+1] = neway;
  73. newax -= ox;
  74. neway -= oy;
  75. switch ((GraphicsPath.JPI)type) {
  76. case GraphicsPath.JPI.SEG_CUBICTO:
  77. point[0] += ax;
  78. point[1] += ay;
  79. point[2] += newax;
  80. point[3] += neway;
  81. break;
  82. case GraphicsPath.JPI.SEG_QUADTO:
  83. point[0] += (newax + ax) / 2;
  84. point[1] += (neway + ay) / 2;
  85. break;
  86. // case GraphicsPath.JPI.SEG_MOVETO:
  87. // case GraphicsPath.JPI.SEG_LINETO:
  88. // case GraphicsPath.JPI.SEG_CLOSE:
  89. // break;
  90. }
  91. ax = newax;
  92. ay = neway;
  93. }
  94. return type;
  95. }
  96. int geom.PathIterator.currentSegment(double[] point) {
  97. int type = _iter.currentSegment(point);
  98. int index = GetIndex(type);
  99. if (index >= 0) {
  100. float ox = (float)point[index];
  101. float oy = (float)point[index+1];
  102. float newax = (float)java.lang.Math.floor(ox + rnd) + norm;
  103. float neway = (float)java.lang.Math.floor(oy + rnd) + norm;
  104. point[index] = newax;
  105. point[index+1] = neway;
  106. newax -= ox;
  107. neway -= oy;
  108. switch ((GraphicsPath.JPI)type) {
  109. case GraphicsPath.JPI.SEG_CUBICTO:
  110. point[0] += ax;
  111. point[1] += ay;
  112. point[2] += newax;
  113. point[3] += neway;
  114. break;
  115. case GraphicsPath.JPI.SEG_QUADTO:
  116. point[0] += (newax + ax) / 2;
  117. point[1] += (neway + ay) / 2;
  118. break;
  119. // case GraphicsPath.JPI.SEG_MOVETO:
  120. // case GraphicsPath.JPI.SEG_LINETO:
  121. // case GraphicsPath.JPI.SEG_CLOSE:
  122. // break;
  123. }
  124. ax = newax;
  125. ay = neway;
  126. }
  127. return type;
  128. }
  129. int geom.PathIterator.getWindingRule() {
  130. return _iter.getWindingRule();
  131. }
  132. #endregion
  133. }
  134. #region Variables
  135. readonly awt.Graphics2D _nativeObject;
  136. PixelOffsetMode _pixelOffsetMode = PixelOffsetMode.Default;
  137. int _textContrast = 4;
  138. TextRenderingHint _textRenderingHint;
  139. readonly Image _image;
  140. readonly Matrix _transform;
  141. GraphicsUnit _pageUnit = GraphicsUnit.Display;
  142. float _pageScale = 1.0f;
  143. readonly Region _clip;
  144. readonly awt.Rectangle _windowRect;
  145. GraphicsState _nextGraphicsState = null;
  146. static readonly float [] _unitConversion = {
  147. 1, // World
  148. 1, // Display
  149. 1, // Pixel
  150. DefaultScreenResolution / 72.0f, // Point
  151. DefaultScreenResolution, // Inch
  152. DefaultScreenResolution / 300.0f,// Document
  153. DefaultScreenResolution / 25.4f // Millimeter
  154. };
  155. static int _isHeadless;
  156. static internal bool IsHeadless {
  157. get {
  158. if (_isHeadless == 0) {
  159. bool isHeadless = awt.GraphicsEnvironment.isHeadless();
  160. if (!isHeadless) {
  161. try {
  162. awt.Toolkit.getDefaultToolkit();
  163. }
  164. catch{
  165. isHeadless = true;
  166. }
  167. }
  168. _isHeadless = isHeadless ? 2 : 1;
  169. }
  170. return _isHeadless > 1;
  171. }
  172. }
  173. #endregion
  174. #if INTPTR_SUPPORT
  175. [ComVisible(false)]
  176. public delegate bool EnumerateMetafileProc (EmfPlusRecordType recordType,
  177. int flags,
  178. int dataSize,
  179. IntPtr data,
  180. PlayRecordCallback callbackData);
  181. [ComVisible (false)]
  182. public delegate bool DrawImageAbort (IntPtr callbackData);
  183. #endif
  184. #region Constr. and Destr.
  185. private Graphics (Image image) {
  186. _nativeObject = (awt.Graphics2D)image.NativeObject.CurrentImage.NativeImage.getGraphics();
  187. _image = image;
  188. _transform = new Matrix ();
  189. NativeObject.setStroke(new DummyStroke());
  190. NativeObject.setRenderingHint(awt.RenderingHints.KEY_COLOR_RENDERING, awt.RenderingHints.VALUE_COLOR_RENDER_QUALITY);
  191. InterpolationMode = InterpolationMode.Bilinear;
  192. TextRenderingHint = TextRenderingHint.SystemDefault;
  193. _windowRect = new awt.Rectangle(_image.Width, _image.Height);
  194. _clip = new Region();
  195. }
  196. #endregion
  197. #region Internal Accessors
  198. static internal float [] UnitConversion {
  199. get {
  200. return _unitConversion;
  201. }
  202. }
  203. static internal int DefaultScreenResolution {
  204. get {
  205. return IsHeadless ? 96 :
  206. awt.Toolkit.getDefaultToolkit().getScreenResolution();
  207. }
  208. }
  209. internal java.awt.Graphics2D NativeObject {
  210. get {
  211. return _nativeObject;
  212. }
  213. }
  214. #endregion
  215. #region FromImage (static accessor)
  216. public static Graphics FromImage (Image image) {
  217. return new Graphics(image);
  218. }
  219. #endregion
  220. #region Workers [INTERNAL]
  221. void DrawShape(Pen pen, awt.Shape shape) {
  222. if (pen == null)
  223. throw new ArgumentNullException("pen");
  224. if (StrokeFactory.CanCreateAdvancedStroke &&
  225. (!pen.CanCreateBasicStroke || !NeedsNormalization)) {
  226. geom.AffineTransform oldT = NativeObject.getTransform();
  227. NativeObject.setTransform(Matrix.IdentityTransform.NativeObject);
  228. try {
  229. geom.AffineTransform t = GetFinalTransform();
  230. if (!oldT.isIdentity()) {
  231. t = (geom.AffineTransform)t.MemberwiseClone();
  232. t.preConcatenate(oldT);
  233. }
  234. double widthsquared = pen.GetSquaredTransformedWidth(t);
  235. bool antiAlias = (SmoothingMode == SmoothingMode.AntiAlias);
  236. bool thin = (widthsquared <= (antiAlias ?
  237. AdvancedStroke.MinPenSizeAASquared :
  238. AdvancedStroke.MinPenSizeSquared));
  239. PenFit penFit = thin ? (antiAlias ? PenFit.ThinAntiAlias : PenFit.Thin) : PenFit.NotThin;
  240. if (NeedsNormalization) {
  241. bool normThin =
  242. widthsquared <= AdvancedStroke.MinPenSizeSquaredNorm;
  243. if (normThin) {
  244. shape = GetNormalizedShape(shape, t);
  245. shape = pen.GetNativeObject(
  246. t, null, penFit).createStrokedShape(shape);
  247. }
  248. else {
  249. shape = pen.GetNativeObject(t, penFit).createStrokedShape(shape);
  250. shape = GetNormalizedShape(shape, null);
  251. }
  252. }
  253. else {
  254. shape = pen.GetNativeObject(t, penFit).createStrokedShape(shape);
  255. }
  256. FillScaledShape(pen.Brush, shape);
  257. }
  258. finally {
  259. NativeObject.setTransform(oldT);
  260. }
  261. }
  262. else {
  263. awt.Stroke oldStroke = NativeObject.getStroke();
  264. NativeObject.setStroke(pen.GetNativeObject(null, PenFit.NotThin));
  265. try {
  266. NativeObject.setPaint(pen.Brush);
  267. geom.AffineTransform oldT = NativeObject.getTransform();
  268. NativeObject.transform(GetFinalTransform());
  269. try {
  270. NativeObject.draw(shape);
  271. }
  272. finally {
  273. NativeObject.setTransform(oldT);
  274. }
  275. }
  276. finally {
  277. NativeObject.setStroke(oldStroke);
  278. }
  279. }
  280. }
  281. void FillShape(Brush paint, awt.Shape shape) {
  282. if (paint == null)
  283. throw new ArgumentNullException("brush");
  284. geom.AffineTransform oldT = null;
  285. if (NeedsNormalization) {
  286. oldT = NativeObject.getTransform();
  287. geom.AffineTransform t = GetFinalTransform();
  288. if (!oldT.isIdentity()) {
  289. t = (geom.AffineTransform) t.MemberwiseClone ();
  290. t.preConcatenate(oldT);
  291. }
  292. shape = GetNormalizedShape(shape, t);
  293. }
  294. else {
  295. geom.AffineTransform t = GetFinalTransform();
  296. if (!t.isIdentity())
  297. shape = t.createTransformedShape(shape);
  298. }
  299. if (oldT != null)
  300. NativeObject.setTransform(Matrix.IdentityTransform.NativeObject);
  301. try {
  302. FillScaledShape(paint, shape);
  303. }
  304. finally {
  305. if (oldT != null)
  306. NativeObject.setTransform(oldT);
  307. }
  308. }
  309. bool NeedsNormalization {
  310. get {
  311. return PixelOffsetMode != PixelOffsetMode.Half &&
  312. PixelOffsetMode != PixelOffsetMode.HighQuality;
  313. }
  314. }
  315. static awt.Shape GetNormalizedShape(awt.Shape shape, geom.AffineTransform t) {
  316. geom.PathIterator iter = new NormalizingPathIterator(shape.getPathIterator(t));
  317. geom.GeneralPath path = new geom.GeneralPath(iter.getWindingRule());
  318. path.append(iter, false);
  319. return path;
  320. }
  321. void FillScaledShape(Brush paint, awt.Shape shape) {
  322. Matrix m = null;
  323. if (!(paint is SolidBrush || paint is HatchBrush) && !_transform.IsIdentity) {
  324. m = paint.BrushTransform;
  325. paint.BrushMultiplyTransform( _transform );
  326. }
  327. try {
  328. NativeObject.setPaint(paint);
  329. NativeObject.fill(shape);
  330. }
  331. finally {
  332. if (m != null)
  333. paint.BrushTransform = m;
  334. }
  335. }
  336. #endregion
  337. #region Dispose
  338. public void Dispose() {
  339. NativeObject.dispose();
  340. }
  341. #endregion
  342. #region Clear
  343. public void Clear (Color color) {
  344. FillScaledShape(new SolidBrush( color ), _clip.NativeObject);
  345. }
  346. #endregion
  347. #region DrawArc
  348. public void DrawArc (Pen pen, Rectangle rect, float startAngle, float sweepAngle) {
  349. DrawArc (pen,
  350. rect.X,
  351. rect.Y,
  352. rect.Width,
  353. rect.Height,
  354. startAngle,
  355. sweepAngle);
  356. }
  357. public void DrawArc (Pen pen, RectangleF rect, float startAngle, float sweepAngle) {
  358. DrawArc (pen,
  359. rect.X,
  360. rect.Y,
  361. rect.Width,
  362. rect.Height,
  363. startAngle,
  364. sweepAngle);
  365. }
  366. public void DrawArc (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle) {
  367. DrawArc(pen,
  368. (float)x,
  369. (float)y,
  370. (float)width,
  371. (float)height,
  372. (float)startAngle,
  373. (float)sweepAngle);
  374. }
  375. public void DrawArc (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) {
  376. GraphicsPath path = new GraphicsPath();
  377. path.AddArc(x, y, width, height, startAngle, sweepAngle);
  378. DrawPath(pen, path);
  379. }
  380. #endregion
  381. #region DrawBezier(s)
  382. public void DrawBezier (Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4) {
  383. DrawBezier(pen, pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
  384. }
  385. public void DrawBezier (Pen pen, Point pt1, Point pt2, Point pt3, Point pt4) {
  386. DrawBezier(pen, pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
  387. }
  388. public void DrawBezier (Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
  389. geom.GeneralPath path = new geom.GeneralPath();
  390. path.moveTo(x1,y1);
  391. path.curveTo(x2,y2,x3,y3,x4,y4);
  392. DrawShape(pen, path);
  393. }
  394. public void DrawBeziers (Pen pen, Point [] points) {
  395. GraphicsPath path = new GraphicsPath();
  396. path.AddBeziers(points);
  397. DrawPath(pen, path);
  398. }
  399. public void DrawBeziers (Pen pen, PointF [] points) {
  400. GraphicsPath path = new GraphicsPath();
  401. path.AddBeziers(points);
  402. DrawPath(pen, path);
  403. }
  404. #endregion
  405. #region DrawClosedCurve
  406. public void DrawClosedCurve (Pen pen, PointF [] points) {
  407. DrawClosedCurve(pen, points, 0.5f, FillMode.Alternate);
  408. }
  409. public void DrawClosedCurve (Pen pen, Point [] points) {
  410. DrawClosedCurve(pen, points, 0.5f, FillMode.Alternate);
  411. }
  412. public void DrawClosedCurve (Pen pen, Point [] points, float tension, FillMode fillmode) {
  413. GraphicsPath path = new GraphicsPath(fillmode);
  414. path.AddClosedCurve(points, tension);
  415. DrawPath(pen, path);
  416. }
  417. public void DrawClosedCurve (Pen pen, PointF [] points, float tension, FillMode fillmode) {
  418. GraphicsPath path = new GraphicsPath(fillmode);
  419. path.AddClosedCurve(points, tension);
  420. DrawPath(pen, path);
  421. }
  422. #endregion
  423. #region DrawCurve
  424. public void DrawCurve (Pen pen, Point [] points) {
  425. DrawCurve(pen, points, 0.5f);
  426. }
  427. public void DrawCurve (Pen pen, PointF [] points) {
  428. DrawCurve(pen, points, 0.5f);
  429. }
  430. public void DrawCurve (Pen pen, PointF [] points, float tension) {
  431. DrawCurve(pen, points, 0, points.Length-1, tension);
  432. }
  433. public void DrawCurve (Pen pen, Point [] points, float tension) {
  434. DrawCurve(pen, points, 0, points.Length-1, tension);
  435. }
  436. public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments) {
  437. DrawCurve(pen, points, offset, numberOfSegments, 0.5f);
  438. }
  439. public void DrawCurve (Pen pen, Point [] points, int offset, int numberOfSegments, float tension) {
  440. GraphicsPath path = new GraphicsPath();
  441. path.AddCurve(points, offset, numberOfSegments, tension);
  442. DrawPath(pen, path);
  443. }
  444. public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments, float tension) {
  445. GraphicsPath path = new GraphicsPath();
  446. path.AddCurve(points, offset, numberOfSegments, tension);
  447. DrawPath(pen, path);
  448. }
  449. #endregion
  450. #region DrawEllipse
  451. public void DrawEllipse (Pen pen, Rectangle rect) {
  452. DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
  453. }
  454. public void DrawEllipse (Pen pen, RectangleF rect) {
  455. DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
  456. }
  457. public void DrawEllipse (Pen pen, int x, int y, int width, int height) {
  458. DrawEllipse(pen,(float)x,(float)y,(float)width,(float)height);
  459. }
  460. public void DrawEllipse (Pen pen, float x, float y, float width, float height) {
  461. DrawShape(pen, new geom.Ellipse2D.Float(x,y,width,height));
  462. }
  463. #endregion
  464. #region DrawIcon
  465. public void DrawIcon (Icon icon, Rectangle targetRect) {
  466. Bitmap b = icon.ToBitmap ();
  467. this.DrawImage (b, targetRect);
  468. }
  469. public void DrawIcon (Icon icon, int x, int y) {
  470. Bitmap b = icon.ToBitmap ();
  471. this.DrawImage (b, x, y);
  472. }
  473. public void DrawIconUnstretched (Icon icon, Rectangle targetRect) {
  474. Bitmap b = icon.ToBitmap ();
  475. this.DrawImageUnscaled (b, targetRect);
  476. }
  477. #endregion
  478. #region DrawImage
  479. public void DrawImage (Image image, Point point) {
  480. DrawImage(image, point.X, point.Y);
  481. }
  482. public void DrawImage (Image image, PointF point) {
  483. DrawImage(image, point.X, point.Y);
  484. }
  485. public void DrawImage (Image image, Point [] destPoints) {
  486. Matrix m = new Matrix(new Rectangle(0, 0, image.Width, image.Height), destPoints);
  487. DrawImage(image, m);
  488. }
  489. public void DrawImage (Image image, PointF [] destPoints) {
  490. Matrix m = new Matrix(new RectangleF(0, 0, image.Width, image.Height), destPoints);
  491. DrawImage(image, m);
  492. }
  493. public void DrawImage (Image image, Rectangle rect) {
  494. DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
  495. }
  496. public void DrawImage (Image image, RectangleF rect) {
  497. DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
  498. }
  499. public void DrawImage (Image image, int x, int y) {
  500. DrawImage(image, (float)x, (float)y);
  501. }
  502. public void DrawImage (Image image, float x, float y) {
  503. if ((image.HorizontalResolution != DpiX) || (image.VerticalResolution != DpiY))
  504. DrawImage( image, x, y,
  505. (float)image.Width * (DpiX / image.HorizontalResolution) / _unitConversion[(int)PageUnit],
  506. (float)image.Height * (DpiY / image.VerticalResolution) / _unitConversion[(int)PageUnit]) ;
  507. else
  508. DrawImage( image, x, y,
  509. (float)image.Width / _unitConversion[(int)PageUnit],
  510. (float)image.Height / _unitConversion[(int)PageUnit] );
  511. }
  512. public void DrawImage (Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit) {
  513. DrawImage(
  514. image,
  515. new Point [] {
  516. new Point( destRect.X, destRect.Y),
  517. new Point( destRect.X + destRect.Width, destRect.Y),
  518. new Point( destRect.X, destRect.Y + destRect.Height)},
  519. srcRect,
  520. srcUnit);
  521. }
  522. public void DrawImage (Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit) {
  523. DrawImage(
  524. image,
  525. new PointF [] {
  526. new PointF( destRect.X, destRect.Y),
  527. new PointF( destRect.X + destRect.Width, destRect.Y),
  528. new PointF( destRect.X, destRect.Y + destRect.Height)},
  529. srcRect,
  530. srcUnit);
  531. }
  532. public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit) {
  533. DrawImage(image, destPoints, srcRect, srcUnit, null);
  534. }
  535. public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit) {
  536. DrawImage(image, destPoints, srcRect, srcUnit, null);
  537. }
  538. [MonoTODO]
  539. public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr) {
  540. //TBD: ImageAttributes
  541. if (srcUnit != GraphicsUnit.Pixel)
  542. throw new NotImplementedException();
  543. // Like in .NET http://dotnet247.com/247reference/msgs/45/227979.aspx
  544. Matrix mx = new Matrix(srcRect, destPoints);
  545. Region region = new Region(srcRect);
  546. DrawImage(image, mx, region);
  547. }
  548. [MonoTODO]
  549. public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr) {
  550. //TBD: ImageAttributes
  551. if (srcUnit != GraphicsUnit.Pixel)
  552. throw new NotImplementedException();
  553. // Like in .NET http://dotnet247.com/247reference/msgs/45/227979.aspx
  554. Matrix mx = new Matrix(srcRect, destPoints);
  555. Region region = new Region(srcRect);
  556. DrawImage(image, mx, region);
  557. }
  558. public void DrawImage (Image image, int x, int y, int width, int height) {
  559. DrawImage(image, (float)x, (float)y, (float)width, (float)height);
  560. }
  561. public void DrawImage (Image image, float x, float y, float width, float height) {
  562. Matrix mx = new Matrix();
  563. mx.Translate((float)x, (float)y);
  564. mx.Scale(width / (float)image.Width, height / (float)image.Height);
  565. DrawImage( image, mx );
  566. }
  567. public void DrawImage (Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit) {
  568. DrawImage(image, new Rectangle(x, y, srcRect.Width, srcRect.Height), srcRect, srcUnit);
  569. }
  570. public void DrawImage (Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit) {
  571. DrawImage(image, new RectangleF(x, y, srcRect.Width, srcRect.Height), srcRect, srcUnit);
  572. }
  573. public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit) {
  574. DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, null);
  575. }
  576. public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit) {
  577. DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, null);
  578. }
  579. [MonoTODO]
  580. public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr) {
  581. //TBD: attributes
  582. DrawImage(
  583. image,
  584. destRect,
  585. new Rectangle(srcX, srcY, srcWidth, srcHeight),
  586. srcUnit);
  587. }
  588. [MonoTODO]
  589. public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs) {
  590. //TBD: attributes
  591. DrawImage(
  592. image,
  593. destRect,
  594. new RectangleF(srcX, srcY, srcWidth, srcHeight),
  595. srcUnit);
  596. }
  597. internal void DrawImage (Image image, Matrix m) {
  598. DrawImage(image, m, null);
  599. }
  600. internal void DrawImage (Image image, Matrix m, Region clip) {
  601. if (clip == null) {
  602. clip = new Region( new RectangleF( 0, 0, image.Width, image.Height ) );
  603. }
  604. geom.AffineTransform t = GetFinalTransform(_transform.NativeObject, PageUnit, 1.0f);
  605. if (!t.isIdentity())
  606. m.NativeObject.preConcatenate(t);
  607. clip.Transform( m );
  608. if (NeedsNormalization) {
  609. Matrix normMatrix = ComputeClipNormalization(clip.GetBounds(this));
  610. clip.Transform(normMatrix);
  611. }
  612. awt.Shape oldClip = NativeObject.getClip();
  613. IntersectScaledClipWithBase(clip);
  614. try {
  615. Matrix mm = ComputeImageNormalization(image, m);
  616. NativeObject.drawImage(image.NativeObject.CurrentImage.NativeImage, mm.NativeObject, null);
  617. }
  618. finally {
  619. NativeObject.setClip( oldClip );
  620. }
  621. }
  622. private static Matrix ComputeImageNormalization(Image img, Matrix m) {
  623. if ( m.IsIdentity )
  624. return m;
  625. //m.Translate( -(m.Elements[0] + m.Elements[2]) / 2.0f, -(m.Elements[3] + m.Elements[1]) / 2.0f, MatrixOrder.Append);
  626. m.Translate(
  627. -(float)(m.NativeObject.getScaleX() + m.NativeObject.getShearX()) / 2.0f,
  628. -(float)(m.NativeObject.getScaleY() + m.NativeObject.getShearY()) / 2.0f, MatrixOrder.Append);
  629. PointF [] p = new PointF[] {
  630. new PointF( 0, 0 ),
  631. new PointF( img.Width, 0 ),
  632. new PointF( 0, img.Height )};
  633. m.TransformPoints(p);
  634. for (int i=0; i < p.Length; i++) {
  635. p[i].X = (float)( p[i].X + 0.5f );
  636. p[i].Y = (float)( p[i].Y + 0.5f );
  637. }
  638. return new Matrix( new Rectangle(0, 0, img.Width, img.Height), p );
  639. }
  640. private static Matrix ComputeClipNormalization(RectangleF rect) {
  641. PointF [] p = new PointF[] {
  642. new PointF( rect.X, rect.Y ),
  643. new PointF( rect.X + rect.Width, rect.Y ),
  644. new PointF( rect.X, rect.Y + rect.Height )};
  645. for (int i=0; i < p.Length; i++) {
  646. p[i].X = (float)Math.Round( p[i].X + 0.5f ) + 0.5f;
  647. p[i].Y = (float)Math.Round( p[i].Y + 0.5f ) + 0.5f;
  648. }
  649. return new Matrix( rect, p );
  650. }
  651. #if INTPTR_SUPPORT
  652. [MonoTODO]
  653. public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
  654. {
  655. throw new NotImplementedException();
  656. }
  657. [MonoTODO]
  658. public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
  659. {
  660. throw new NotImplementedException();
  661. }
  662. [MonoTODO]
  663. public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
  664. {
  665. throw new NotImplementedException();
  666. }
  667. #endif
  668. #if INTPTR_SUPPORT
  669. [MonoTODO]
  670. public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
  671. {
  672. throw new NotImplementedException();
  673. }
  674. #endif
  675. #if INTPTR_SUPPORT
  676. public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
  677. {
  678. //TBD:units,attributes, callback
  679. java.awt.Graphics2D g = (java.awt.Graphics2D)nativeObject;
  680. g.drawImage(image.NativeObject,destRect.X,destRect.Y,destRect.Width,destRect.Height,srcX,srcY,srcWidth,srcHeight,null);
  681. }
  682. public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
  683. {
  684. //TBD:units,attributes, callback
  685. java.awt.Graphics2D g = (java.awt.Graphics2D)nativeObject;
  686. g.drawImage(image.NativeObject,
  687. (int)destRect.X,
  688. (int)destRect.Y,
  689. (int)destRect.Width,
  690. (int)destRect.Height,
  691. (int)srcX,
  692. (int)srcY,
  693. (int)srcWidth,
  694. (int)srcHeight,null);
  695. }
  696. public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
  697. {
  698. //TBD:units,attributes, callback
  699. java.awt.Graphics2D g = (java.awt.Graphics2D)nativeObject;
  700. g.drawImage(image.NativeObject,
  701. (int)destRect.X,
  702. (int)destRect.Y,
  703. (int)destRect.Width,
  704. (int)destRect.Height,
  705. (int)srcX,
  706. (int)srcY,
  707. (int)srcWidth,
  708. (int)srcHeight,null);
  709. }
  710. public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
  711. {
  712. //TBD:units,attributes, callback
  713. java.awt.Graphics2D g = (java.awt.Graphics2D)nativeObject;
  714. g.drawImage(image.NativeObject,
  715. destRect.X,
  716. destRect.Y,
  717. destRect.Width,
  718. destRect.Height,
  719. srcX,
  720. srcY,
  721. srcWidth,
  722. srcHeight,null);
  723. }
  724. #endif
  725. public void DrawImageUnscaled (Image image, Point point)
  726. {
  727. DrawImageUnscaled (image, point.X, point.Y);
  728. }
  729. public void DrawImageUnscaled (Image image, Rectangle rect) {
  730. DrawImageUnscaled (image, rect.X, rect.Y, rect.Width, rect.Height);
  731. }
  732. public void DrawImageUnscaled (Image image, int x, int y) {
  733. DrawImage (image, x, y, image.Width, image.Height);
  734. }
  735. public void DrawImageUnscaled (Image image, int x, int y, int width, int height) {
  736. Image tmpImg = new Bitmap (width, height);
  737. Graphics g = FromImage (tmpImg);
  738. g.DrawImage (image, 0, 0, image.Width, image.Height);
  739. this.DrawImage (tmpImg, x, y, width, height);
  740. tmpImg.Dispose ();
  741. g.Dispose ();
  742. }
  743. #endregion
  744. #region DrawLine
  745. public void DrawLine (Pen pen, PointF pt1, PointF pt2) {
  746. DrawLine(pen,pt1.X,pt1.Y,pt2.X,pt2.Y);
  747. }
  748. public void DrawLine (Pen pen, Point pt1, Point pt2) {
  749. DrawLine(pen,(float)pt1.X,(float)pt1.Y,(float)pt2.X,(float)pt2.Y);
  750. }
  751. public void DrawLine (Pen pen, int x1, int y1, int x2, int y2) {
  752. DrawLine(pen,(float)x1,(float)y1,(float)x2,(float)y2);
  753. }
  754. public void DrawLine (Pen pen, float x1, float y1, float x2, float y2) {
  755. DrawShape(pen, new geom.Line2D.Float(x1,y1,x2,y2));
  756. }
  757. public void DrawLines (Pen pen, PointF [] points) {
  758. GraphicsPath path = new GraphicsPath();
  759. path.AddLines(points);
  760. DrawShape(pen, path);
  761. }
  762. public void DrawLines (Pen pen, Point [] points) {
  763. GraphicsPath path = new GraphicsPath();
  764. path.AddLines(points);
  765. DrawShape(pen, path);
  766. }
  767. #endregion
  768. #region DrawPath
  769. public void DrawPath (Pen pen, GraphicsPath path) {
  770. DrawShape(pen, path);
  771. }
  772. #endregion
  773. #region DrawPie
  774. public void DrawPie (Pen pen, Rectangle rect, float startAngle, float sweepAngle) {
  775. DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
  776. }
  777. public void DrawPie (Pen pen, RectangleF rect, float startAngle, float sweepAngle) {
  778. DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
  779. }
  780. public void DrawPie (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) {
  781. GraphicsPath path = new GraphicsPath();
  782. path.AddPie(x, y, width, height, startAngle, sweepAngle);
  783. DrawPath(pen, path);
  784. }
  785. public void DrawPie (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle) {
  786. DrawPie(pen,(float)x,(float)y,(float)width,(float)height,(float)startAngle,(float)sweepAngle);
  787. }
  788. #endregion
  789. #region DrawPolygon
  790. public void DrawPolygon (Pen pen, Point [] points) {
  791. GraphicsPath path = new GraphicsPath();
  792. path.AddPolygon(points);
  793. DrawPath(pen, path);
  794. }
  795. public void DrawPolygon (Pen pen, PointF [] points) {
  796. GraphicsPath path = new GraphicsPath();
  797. path.AddPolygon(points);
  798. DrawPath(pen, path);
  799. }
  800. #endregion
  801. #region DrawRectangle(s)
  802. internal void DrawRectangle (Pen pen, RectangleF rect) {
  803. DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
  804. }
  805. public void DrawRectangle (Pen pen, Rectangle rect) {
  806. DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
  807. }
  808. public void DrawRectangle (Pen pen, float x, float y, float width, float height) {
  809. DrawShape(pen, new geom.Rectangle2D.Float(x,y,width,height));
  810. }
  811. public void DrawRectangle (Pen pen, int x, int y, int width, int height) {
  812. DrawRectangle (pen,(float) x,(float) y,(float) width,(float) height);
  813. }
  814. public void DrawRectangles (Pen pen, RectangleF [] rects) {
  815. foreach(RectangleF r in rects)
  816. DrawRectangle (pen, r.Left, r.Top, r.Width, r.Height);
  817. }
  818. public void DrawRectangles (Pen pen, Rectangle [] rects) {
  819. foreach(Rectangle r in rects)
  820. DrawRectangle (pen, r.Left, r.Top, r.Width, r.Height);
  821. }
  822. #endregion
  823. #region DrawString
  824. public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle) {
  825. DrawString(s, font, brush, layoutRectangle.X, layoutRectangle.Y, layoutRectangle.Width, layoutRectangle.Height, null);
  826. }
  827. public void DrawString (string s, Font font, Brush brush, PointF point) {
  828. DrawString(s, font, brush, point.X, point.Y, float.PositiveInfinity, float.PositiveInfinity, null);
  829. }
  830. public void DrawString (string s, Font font, Brush brush, PointF point, StringFormat format) {
  831. DrawString(s, font, brush, point.X, point.Y, float.PositiveInfinity, float.PositiveInfinity, format);
  832. }
  833. public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) {
  834. DrawString(s, font, brush, layoutRectangle.X, layoutRectangle.Y, layoutRectangle.Width, layoutRectangle.Height, format);
  835. }
  836. public void DrawString (string s, Font font, Brush brush, float x, float y) {
  837. DrawString(s, font, brush, x, y, float.PositiveInfinity, float.PositiveInfinity, null);
  838. }
  839. public void DrawString (string s, Font font, Brush brush, float x, float y, StringFormat format) {
  840. DrawString(s, font, brush, x, y, float.PositiveInfinity, float.PositiveInfinity, format);
  841. }
  842. void DrawString (string s, Font font, Brush brush,
  843. float x, float y, float width, float height,
  844. StringFormat format) {
  845. if (brush == null)
  846. throw new ArgumentNullException("brush");
  847. if (font == null)
  848. throw new ArgumentNullException("font");
  849. if (format != null && format.LineAlignment != StringAlignment.Near) {
  850. SizeF sizeF = MeasureString(s, font, format, width, height, null);
  851. float lineAWidth = width;
  852. float lineAHeight = height;
  853. if (float.IsPositiveInfinity(width))
  854. lineAWidth = lineAHeight = 0;
  855. float wdelta = format.IsVertical ? lineAWidth - sizeF.Width : lineAHeight - sizeF.Height;
  856. float pdelta = format.LineAlignment == StringAlignment.Center ? wdelta/2 : wdelta;
  857. if (format.IsVertical) {
  858. if (!(format.IsRightToLeft && format.LineAlignment == StringAlignment.Far))
  859. x += pdelta;
  860. if (!float.IsPositiveInfinity(width))
  861. width -= wdelta;
  862. }
  863. else {
  864. y += pdelta;
  865. if (!float.IsPositiveInfinity(width))
  866. height -= wdelta;
  867. }
  868. }
  869. awt.Paint oldP = NativeObject.getPaint();
  870. NativeObject.setPaint(brush);
  871. try {
  872. geom.AffineTransform oldT = NativeObject.getTransform();
  873. NativeObject.transform(GetFinalTransform());
  874. try {
  875. bool noclip = float.IsPositiveInfinity(width) || (format != null && format.NoClip);
  876. awt.Shape oldClip = null;
  877. if (!noclip) {
  878. oldClip = NativeObject.getClip();
  879. NativeObject.clip(new geom.Rectangle2D.Float(x, y, width, height));
  880. }
  881. try {
  882. TextLineIterator iter = new TextLineIterator(s, font, NativeObject.getFontRenderContext(), format, width, height);
  883. NativeObject.transform(iter.Transform);
  884. for (LineLayout layout = iter.NextLine(); layout != null; layout = iter.NextLine()) {
  885. layout.Draw(NativeObject, x, y);
  886. }
  887. }
  888. finally {
  889. if (!noclip)
  890. NativeObject.setClip(oldClip);
  891. }
  892. }
  893. finally {
  894. NativeObject.setTransform(oldT);
  895. }
  896. }
  897. finally {
  898. NativeObject.setPaint(oldP);
  899. }
  900. }
  901. #endregion
  902. #region Container
  903. void PushGraphicsState(GraphicsState state) {
  904. state.Next = _nextGraphicsState;
  905. _nextGraphicsState = state;
  906. }
  907. GraphicsState PopGraphicsState() {
  908. GraphicsState state = _nextGraphicsState;
  909. _nextGraphicsState = _nextGraphicsState.Next;
  910. return state;
  911. }
  912. bool ContainsGraphicsState(GraphicsState state) {
  913. GraphicsState gs = _nextGraphicsState;
  914. while(gs != null) {
  915. if (gs == state)
  916. return true;
  917. gs = gs.Next;
  918. }
  919. return false;
  920. }
  921. public void EndContainer (GraphicsContainer container) {
  922. Restore(container.StateObject);
  923. }
  924. public GraphicsContainer BeginContainer () {
  925. return new GraphicsContainer(Save(Matrix.IdentityTransform, true));
  926. }
  927. public GraphicsContainer BeginContainer (Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit) {
  928. Matrix containerTransfrom =
  929. new Matrix( srcrect,
  930. new Point [] { new Point (dstrect.X, dstrect.Y),
  931. new Point (dstrect.X + dstrect.Width, dstrect.Y),
  932. new Point (dstrect.X, dstrect.Y + dstrect.Height) });
  933. float scale = _unitConversion[ (int)PageUnit ] / _unitConversion[ (int)unit ];
  934. containerTransfrom.Scale(scale, scale);
  935. return new GraphicsContainer(Save(containerTransfrom, true));
  936. }
  937. public GraphicsContainer BeginContainer (RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit) {
  938. Matrix containerTransfrom =
  939. new Matrix( srcrect,
  940. new PointF [] { new PointF (dstrect.X, dstrect.Y),
  941. new PointF (dstrect.X + dstrect.Width, dstrect.Y),
  942. new PointF (dstrect.X, dstrect.Y + dstrect.Height) });
  943. float scale = _unitConversion[ (int)PageUnit ] / _unitConversion[ (int)unit ];
  944. containerTransfrom.Scale(scale, scale);
  945. return new GraphicsContainer(Save(containerTransfrom, true));
  946. }
  947. GraphicsState Save(Matrix matrix, bool resetState) {
  948. GraphicsState graphicsState = new GraphicsState(this, matrix, resetState);
  949. PushGraphicsState( graphicsState );
  950. return graphicsState;
  951. }
  952. public GraphicsState Save () {
  953. return Save(Matrix.IdentityTransform, false);
  954. }
  955. public void Restore (GraphicsState graphicsState) {
  956. if (ContainsGraphicsState(graphicsState)) {
  957. GraphicsState gs = PopGraphicsState();
  958. while ( gs != graphicsState )
  959. gs = PopGraphicsState();
  960. graphicsState.RestoreState(this);
  961. }
  962. }
  963. #endregion
  964. #region Metafiles Staff
  965. [MonoTODO]
  966. public void AddMetafileComment (byte [] data) {
  967. throw new NotImplementedException ();
  968. }
  969. #if INTPTR_SUPPORT
  970. [MonoTODO]
  971. public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback)
  972. {
  973. throw new NotImplementedException ();
  974. }
  975. [MonoTODO]
  976. public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback)
  977. {
  978. throw new NotImplementedException ();
  979. }
  980. [MonoTODO]
  981. public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback)
  982. {
  983. throw new NotImplementedException ();
  984. }
  985. [MonoTODO]
  986. public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback)
  987. {
  988. throw new NotImplementedException ();
  989. }
  990. [MonoTODO]
  991. public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback)
  992. {
  993. throw new NotImplementedException ();
  994. }
  995. [MonoTODO]
  996. public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback)
  997. {
  998. throw new NotImplementedException ();
  999. }
  1000. [MonoTODO]
  1001. public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
  1002. {
  1003. throw new NotImplementedException ();
  1004. }
  1005. [MonoTODO]
  1006. public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData)
  1007. {
  1008. throw new NotImplementedException ();
  1009. }
  1010. [MonoTODO]
  1011. public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
  1012. {
  1013. throw new NotImplementedException ();
  1014. }
  1015. [MonoTODO]
  1016. public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
  1017. {
  1018. throw new NotImplementedException ();
  1019. }
  1020. [MonoTODO]
  1021. public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
  1022. {
  1023. throw new NotImplementedException ();
  1024. }
  1025. [MonoTODO]
  1026. public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData)
  1027. {
  1028. throw new NotImplementedException ();
  1029. }
  1030. [MonoTODO]
  1031. public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
  1032. {
  1033. throw new NotImplementedException ();
  1034. }
  1035. [MonoTODO]
  1036. public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
  1037. {
  1038. throw new NotImplementedException ();
  1039. }
  1040. [MonoTODO]
  1041. public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
  1042. {
  1043. throw new NotImplementedException ();
  1044. }
  1045. [MonoTODO]
  1046. public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
  1047. {
  1048. throw new NotImplementedException ();
  1049. }
  1050. [MonoTODO]
  1051. public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
  1052. {
  1053. throw new NotImplementedException ();
  1054. }
  1055. [MonoTODO]
  1056. public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
  1057. {
  1058. throw new NotImplementedException ();
  1059. }
  1060. [MonoTODO]
  1061. public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1062. {
  1063. throw new NotImplementedException ();
  1064. }
  1065. [MonoTODO]
  1066. public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1067. {
  1068. throw new NotImplementedException ();
  1069. }
  1070. [MonoTODO]
  1071. public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1072. {
  1073. throw new NotImplementedException ();
  1074. }
  1075. [MonoTODO]
  1076. public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1077. {
  1078. throw new NotImplementedException ();
  1079. }
  1080. [MonoTODO]
  1081. public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1082. {
  1083. throw new NotImplementedException ();
  1084. }
  1085. [MonoTODO]
  1086. public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1087. {
  1088. throw new NotImplementedException ();
  1089. }
  1090. [MonoTODO]
  1091. public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
  1092. {
  1093. throw new NotImplementedException ();
  1094. }
  1095. [MonoTODO]
  1096. public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
  1097. {
  1098. throw new NotImplementedException ();
  1099. }
  1100. [MonoTODO]
  1101. public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
  1102. {
  1103. throw new NotImplementedException ();
  1104. }
  1105. [MonoTODO]
  1106. public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
  1107. {
  1108. throw new NotImplementedException ();
  1109. }
  1110. [MonoTODO]
  1111. public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
  1112. {
  1113. throw new NotImplementedException ();
  1114. }
  1115. [MonoTODO]
  1116. public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
  1117. {
  1118. throw new NotImplementedException ();
  1119. }
  1120. [MonoTODO]
  1121. public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1122. {
  1123. throw new NotImplementedException ();
  1124. }
  1125. [MonoTODO]
  1126. public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1127. {
  1128. throw new NotImplementedException ();
  1129. }
  1130. [MonoTODO]
  1131. public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1132. {
  1133. throw new NotImplementedException ();
  1134. }
  1135. [MonoTODO]
  1136. public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1137. {
  1138. throw new NotImplementedException ();
  1139. }
  1140. [MonoTODO]
  1141. public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1142. {
  1143. throw new NotImplementedException ();
  1144. }
  1145. [MonoTODO]
  1146. public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
  1147. {
  1148. throw new NotImplementedException ();
  1149. }
  1150. #endif
  1151. #endregion
  1152. #region ExcludeClip
  1153. void ExcludeClip(geom.Area area) {
  1154. geom.AffineTransform t = GetFinalTransform();
  1155. if (!t.isIdentity()) {
  1156. area = (geom.Area) area.MemberwiseClone ();
  1157. area.transform(t);
  1158. }
  1159. _clip.NativeObject.subtract(area);
  1160. RestoreBaseClip();
  1161. NativeObject.clip(_clip);
  1162. }
  1163. public void ExcludeClip (Rectangle rect) {
  1164. ExcludeClip(new geom.Area(rect.NativeObject));
  1165. }
  1166. public void ExcludeClip (Region region) {
  1167. if (region == null)
  1168. throw new ArgumentNullException("region");
  1169. ExcludeClip(region.NativeObject);
  1170. }
  1171. #endregion
  1172. #region FillClosedCurve
  1173. public void FillClosedCurve (Brush brush, PointF [] points) {
  1174. FillClosedCurve (brush, points, FillMode.Alternate);
  1175. }
  1176. public void FillClosedCurve (Brush brush, Point [] points) {
  1177. FillClosedCurve (brush, points, FillMode.Alternate);
  1178. }
  1179. public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode) {
  1180. FillClosedCurve (brush, points, fillmode, 0.5f);
  1181. }
  1182. public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode) {
  1183. FillClosedCurve (brush, points, fillmode, 0.5f);
  1184. }
  1185. public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode, float tension) {
  1186. GraphicsPath path = new GraphicsPath(fillmode);
  1187. path.AddClosedCurve(points, tension);
  1188. FillPath(brush, path);
  1189. }
  1190. public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode, float tension) {
  1191. GraphicsPath path = new GraphicsPath(fillmode);
  1192. path.AddClosedCurve(points, tension);
  1193. FillPath(brush, path);
  1194. }
  1195. #endregion
  1196. #region FillEllipse
  1197. public void FillEllipse (Brush brush, Rectangle rect) {
  1198. FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
  1199. }
  1200. public void FillEllipse (Brush brush, RectangleF rect) {
  1201. FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
  1202. }
  1203. public void FillEllipse (Brush brush, float x, float y, float width, float height) {
  1204. FillShape(brush,new java.awt.geom.Ellipse2D.Float(x,y,width,height));
  1205. }
  1206. public void FillEllipse (Brush brush, int x, int y, int width, int height) {
  1207. FillEllipse (brush,(float)x,(float)y,(float)width,(float)height);
  1208. }
  1209. #endregion
  1210. #region FillPath
  1211. public void FillPath (Brush brush, GraphicsPath path) {
  1212. if (path == null)
  1213. throw new ArgumentNullException("path");
  1214. FillShape(brush,path);
  1215. }
  1216. #endregion
  1217. #region FillPie
  1218. public void FillPie (Brush brush, Rectangle rect, float startAngle, float sweepAngle) {
  1219. FillPie(brush,(float)rect.X,(float)rect.Y,(float)rect.Width,(float)rect.Height,(float)startAngle,(float)sweepAngle);
  1220. }
  1221. public void FillPie (Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle) {
  1222. FillPie(brush,(float)x,(float)y,(float)width,(float)height,(float)startAngle,(float)sweepAngle);
  1223. }
  1224. public void FillPie (Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) {
  1225. GraphicsPath path = new GraphicsPath();
  1226. path.AddPie(x, y, width, height, startAngle, sweepAngle);
  1227. FillPath(brush, path);
  1228. }
  1229. #endregion
  1230. #region FillPolygon
  1231. public void FillPolygon (Brush brush, PointF [] points) {
  1232. FillPolygon(brush, points, FillMode.Alternate);
  1233. }
  1234. public void FillPolygon (Brush brush, Point [] points) {
  1235. FillPolygon(brush, points, FillMode.Alternate);
  1236. }
  1237. public void FillPolygon (Brush brush, Point [] points, FillMode fillMode) {
  1238. GraphicsPath path = new GraphicsPath(fillMode);
  1239. path.AddPolygon(points);
  1240. FillPath(brush,path);
  1241. }
  1242. public void FillPolygon (Brush brush, PointF [] points, FillMode fillMode) {
  1243. GraphicsPath path = new GraphicsPath(fillMode);
  1244. path.AddPolygon(points);
  1245. FillPath(brush,path);
  1246. }
  1247. #endregion
  1248. #region FillRectangle
  1249. public void FillRectangle (Brush brush, RectangleF rect) {
  1250. FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
  1251. }
  1252. public void FillRectangle (Brush brush, Rectangle rect) {
  1253. FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
  1254. }
  1255. public void FillRectangle (Brush brush, int x, int y, int width, int height) {
  1256. FillRectangle(brush,(float)x,(float)y,(float)width,(float)height);
  1257. }
  1258. public void FillRectangle (Brush brush, float x, float y, float width, float height) {
  1259. FillShape(brush,new java.awt.geom.Rectangle2D.Float(x,y,width,height));
  1260. }
  1261. public void FillRectangles (Brush brush, Rectangle [] rects) {
  1262. GraphicsPath path = new GraphicsPath();
  1263. path.AddRectangles(rects);
  1264. FillPath(brush,path);
  1265. }
  1266. public void FillRectangles (Brush brush, RectangleF [] rects) {
  1267. GraphicsPath path = new GraphicsPath();
  1268. path.AddRectangles(rects);
  1269. FillPath(brush,path);
  1270. }
  1271. #endregion
  1272. #region FillRegion
  1273. public void FillRegion (Brush brush, Region region) {
  1274. FillShape(brush,region);
  1275. }
  1276. #endregion
  1277. public void Flush () {
  1278. Flush (FlushIntention.Flush);
  1279. }
  1280. public void Flush (FlushIntention intention) {
  1281. if (_image != null)
  1282. _image.NativeObject.CurrentImage.NativeImage.flush();
  1283. }
  1284. #if INTPTR_SUPPORTED
  1285. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1286. [MonoTODO]
  1287. public void ReleaseHdc (IntPtr hdc)
  1288. {
  1289. throw new NotImplementedException();
  1290. }
  1291. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1292. [MonoTODO]
  1293. public void ReleaseHdcInternal (IntPtr hdc)
  1294. {
  1295. throw new NotImplementedException ();
  1296. }
  1297. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1298. [MonoTODO]
  1299. public static Graphics FromHdc (IntPtr hdc)
  1300. {
  1301. throw new NotImplementedException();
  1302. }
  1303. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1304. [MonoTODO]
  1305. public static Graphics FromHdc (IntPtr hdc, IntPtr hdevice)
  1306. {
  1307. throw new NotImplementedException ();
  1308. }
  1309. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1310. [MonoTODO]
  1311. public static Graphics FromHdcInternal (IntPtr hdc)
  1312. {
  1313. throw new NotImplementedException ();
  1314. }
  1315. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1316. [MonoTODO]
  1317. public static Graphics FromHwnd (IntPtr hwnd)
  1318. {
  1319. throw new NotImplementedException();
  1320. }
  1321. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1322. [MonoTODO]
  1323. public static Graphics FromHwndInternal (IntPtr hwnd)
  1324. {
  1325. throw new NotImplementedException ();
  1326. }
  1327. [MonoTODO]
  1328. internal static Graphics FromXDrawable (IntPtr drawable, IntPtr display)
  1329. {
  1330. throw new NotImplementedException();
  1331. }
  1332. [MonoTODO]
  1333. public static IntPtr GetHalftonePalette ()
  1334. {
  1335. throw new NotImplementedException ();
  1336. }
  1337. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1338. [MonoTODO]
  1339. public IntPtr GetHdc ()
  1340. {
  1341. throw new NotImplementedException();
  1342. }
  1343. #endif
  1344. #region GetNearestColor
  1345. [MonoTODO]
  1346. public Color GetNearestColor (Color color) {
  1347. throw new NotImplementedException();
  1348. }
  1349. #endregion
  1350. #region IntersectClip
  1351. void IntersectClip (geom.Area area) {
  1352. geom.AffineTransform t = GetFinalTransform();
  1353. if (!t.isIdentity()) {
  1354. area = (geom.Area) area.MemberwiseClone ();
  1355. area.transform(t);
  1356. }
  1357. _clip.NativeObject.intersect(area);
  1358. RestoreBaseClip();
  1359. NativeObject.clip(_clip);
  1360. }
  1361. public void IntersectClip (Region region) {
  1362. if (region == null)
  1363. throw new ArgumentNullException("region");
  1364. IntersectClip(region.NativeObject);
  1365. }
  1366. public void IntersectClip (RectangleF rect) {
  1367. IntersectClip(new geom.Area(rect.NativeObject));
  1368. }
  1369. public void IntersectClip (Rectangle rect) {
  1370. IntersectClip(new geom.Area(rect.NativeObject));
  1371. }
  1372. #endregion
  1373. #region IsVisible
  1374. public bool IsVisible (Point point) {
  1375. return IsVisible(point.X,point.Y);
  1376. }
  1377. public bool IsVisible (RectangleF rect) {
  1378. return IsVisible ((float)rect.X,(float)rect.Y,(float)rect.Width,(float)rect.Height);
  1379. }
  1380. public bool IsVisible (PointF point) {
  1381. return IsVisible(point.X,point.Y);
  1382. }
  1383. public bool IsVisible (Rectangle rect) {
  1384. return IsVisible ((float)rect.X,(float)rect.Y,(float)rect.Width,(float)rect.Height);
  1385. }
  1386. public bool IsVisible (float x, float y) {
  1387. double dx = x;
  1388. double dy = y;
  1389. geom.AffineTransform t = GetFinalTransform();
  1390. if (!t.isIdentity()) {
  1391. double[] p = new double[] {dx, dy};
  1392. t.transform(p, 0, p, 0, 1);
  1393. dx = p[0];
  1394. dy = p[1];
  1395. }
  1396. if (!_clip.NativeObject.contains(dx, dy))
  1397. return false;
  1398. awt.Shape clip = NativeObject.getClip();
  1399. if (clip == null)
  1400. return true;
  1401. return clip.contains(dx, dy);
  1402. }
  1403. public bool IsVisible (int x, int y) {
  1404. return IsVisible ((float)x,(float)y);
  1405. }
  1406. public bool IsVisible (float x, float y, float width, float height) {
  1407. geom.AffineTransform t = GetFinalTransform();
  1408. geom.Rectangle2D r = new geom.Rectangle2D.Float(x, y, width, height);
  1409. if (!t.isIdentity())
  1410. r = t.createTransformedShape(r).getBounds2D();
  1411. return NativeObject.hitClip(
  1412. (int)(r.getX()+0.5), (int)(r.getY()+0.5),
  1413. (int)(r.getWidth()+0.5), (int)(r.getHeight()+0.5))
  1414. && _clip.NativeObject.intersects(r);
  1415. }
  1416. public bool IsVisible (int x, int y, int width, int height) {
  1417. return IsVisible ((float)x,(float)y,(float)width,(float)height);
  1418. }
  1419. #endregion
  1420. #region MeasureCharacterRanges
  1421. public Region [] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat) {
  1422. if (stringFormat == null)
  1423. throw new ArgumentException("stringFormat");
  1424. CharacterRange[] ranges = stringFormat.CharRanges;
  1425. if (ranges == null || ranges.Length == 0)
  1426. return new Region[0];
  1427. GraphicsPath[] pathes = new GraphicsPath[ranges.Length];
  1428. for (int i = 0; i < pathes.Length; i++)
  1429. pathes[i] = new GraphicsPath();
  1430. TextLineIterator iter = new TextLineIterator(text, font, NativeObject.getFontRenderContext(),
  1431. stringFormat, layoutRect.Width, layoutRect.Height);
  1432. for (LineLayout layout = iter.NextLine(); layout != null; layout = iter.NextLine()) {
  1433. for (int i = 0; i < ranges.Length; i++) {
  1434. int start = ranges[i].First;
  1435. int length = ranges[i].Length;
  1436. start -= iter.CharsConsumed;
  1437. int limit = start + length;
  1438. int layoutStart = iter.CurrentPosition - layout.CharacterCount;
  1439. if (start < iter.CurrentPosition && limit > layoutStart) {
  1440. float layoutOffset;
  1441. if (start > layoutStart)
  1442. layoutOffset = iter.GetAdvanceBetween(layoutStart, start);
  1443. else {
  1444. layoutOffset = 0;
  1445. start = layoutStart;
  1446. }
  1447. float width = (limit < iter.CurrentPosition) ?
  1448. iter.GetAdvanceBetween(start, limit) :
  1449. layout.Width - layoutOffset;
  1450. float height = layout.Ascent + layout.Descent;
  1451. float x = layout.NativeX;
  1452. float y = layout.NativeY;
  1453. if (stringFormat.IsVertical) {
  1454. y += layoutOffset;
  1455. x -= layout.Descent;
  1456. }
  1457. else {
  1458. x += layoutOffset;
  1459. y -= layout.Ascent;
  1460. }
  1461. if (layout.AccumulatedHeight + height > iter.WrapHeight) {
  1462. float diff = iter.WrapHeight - layout.AccumulatedHeight;
  1463. if (stringFormat.IsVertical && stringFormat.IsRightToLeft) {
  1464. x += diff;
  1465. height -= diff;
  1466. }
  1467. else
  1468. height = diff;
  1469. }
  1470. if (stringFormat.IsVertical)
  1471. pathes[i].AddRectangle(x + layoutRect.X, y + layoutRect.Y, height, width);
  1472. else
  1473. pathes[i].AddRectangle(x + layoutRect.X, y + layoutRect.Y, width, height);
  1474. }
  1475. }
  1476. }
  1477. geom.AffineTransform lineAlignT = iter.CalcLineAlignmentTransform();
  1478. if (lineAlignT != null) {
  1479. for (int i = 0; i < pathes.Length; i++)
  1480. pathes[i].NativeObject.transform(lineAlignT);
  1481. }
  1482. Region[] regions = new Region[ranges.Length];
  1483. for (int i = 0; i < regions.Length; i++)
  1484. regions[i] = new Region(pathes[i]);
  1485. return regions;
  1486. }
  1487. #endregion
  1488. #region MeasureString
  1489. public SizeF MeasureString (string text, Font font) {
  1490. return MeasureString(text, font, null, float.PositiveInfinity, float.PositiveInfinity, null);
  1491. }
  1492. public SizeF MeasureString (string text, Font font, SizeF layoutArea) {
  1493. return MeasureString(text, font, layoutArea, null);
  1494. }
  1495. public SizeF MeasureString (string text, Font font, int width) {
  1496. return MeasureString(text, font, width, null);
  1497. }
  1498. public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat format) {
  1499. return MeasureString(text, font, format, layoutArea.Width, layoutArea.Height, null);
  1500. }
  1501. public SizeF MeasureString (string text, Font font, int width, StringFormat format) {
  1502. return MeasureString(text, font, format, width, float.PositiveInfinity, null);
  1503. }
  1504. public SizeF MeasureString (string text, Font font, PointF origin, StringFormat format) {
  1505. return MeasureString(text, font, format, float.PositiveInfinity, float.PositiveInfinity, null);
  1506. }
  1507. SizeF MeasureString (string text, Font font, StringFormat format, float width, float height, int[] statistics) {
  1508. if (statistics != null) {
  1509. statistics[0] = 0;
  1510. statistics[1] = 0;
  1511. }
  1512. TextLineIterator iter = new TextLineIterator(text, font, NativeObject.getFontRenderContext(), format, width, height);
  1513. float mwidth = 0;
  1514. int linesFilled = 0;
  1515. for (LineLayout layout = iter.NextLine(); layout != null; layout = iter.NextLine()) {
  1516. linesFilled ++;
  1517. float w = layout.MeasureWidth;
  1518. if (w > mwidth)
  1519. mwidth = w;
  1520. }
  1521. if (linesFilled == 0)
  1522. return SizeF.Empty;
  1523. float mheight = iter.AccumulatedHeight;
  1524. if (format != null) {
  1525. if (format.IsVertical) {
  1526. float temp = mheight;
  1527. mheight = mwidth;
  1528. mwidth = temp;
  1529. }
  1530. }
  1531. if (!(format != null && format.NoClip)) {
  1532. if (mwidth > width)
  1533. mwidth = width;
  1534. if (mheight > height)
  1535. mheight = height;
  1536. }
  1537. if (statistics != null) {
  1538. statistics[0] = linesFilled;
  1539. statistics[1] = iter.CharsConsumed;
  1540. }
  1541. return new SizeF(mwidth, mheight);
  1542. }
  1543. public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat, out int charactersFitted, out int linesFilled) {
  1544. linesFilled = 0;
  1545. charactersFitted = 0;
  1546. int[] statistics = new int[2];
  1547. SizeF sz = MeasureString(text, font, stringFormat, layoutArea.Width, layoutArea.Height, statistics);
  1548. linesFilled = statistics[0];
  1549. charactersFitted = statistics[1];
  1550. return sz;
  1551. }
  1552. #endregion
  1553. #region MultiplyTransform
  1554. public void MultiplyTransform (Matrix matrix) {
  1555. MultiplyTransform (matrix, MatrixOrder.Prepend);
  1556. }
  1557. public void MultiplyTransform (Matrix matrix, MatrixOrder order) {
  1558. ConcatenateTransform(matrix.NativeObject, order);
  1559. }
  1560. #endregion
  1561. #region Reset (Clip and Transform)
  1562. public void ResetClip () {
  1563. _clip.MakeInfinite();
  1564. RestoreBaseClip();
  1565. NativeObject.clip(_clip);
  1566. }
  1567. public void ResetTransform () {
  1568. _transform.Reset();
  1569. }
  1570. #endregion
  1571. #region RotateTransform
  1572. public void RotateTransform (float angle) {
  1573. RotateTransform (angle, MatrixOrder.Prepend);
  1574. }
  1575. public void RotateTransform (float angle, MatrixOrder order) {
  1576. ConcatenateTransform(
  1577. geom.AffineTransform.getRotateInstance(java.lang.Math.toRadians(angle)),
  1578. order);
  1579. }
  1580. #endregion
  1581. #region ScaleTransform
  1582. public void ScaleTransform (float sx, float sy) {
  1583. ScaleTransform (sx, sy, MatrixOrder.Prepend);
  1584. }
  1585. public void ScaleTransform (float sx, float sy, MatrixOrder order) {
  1586. ConcatenateTransform(
  1587. geom.AffineTransform.getScaleInstance(sx, sy),
  1588. order);
  1589. }
  1590. #endregion
  1591. #region SetClip [Must be reviewed - more abstraction needed]
  1592. public void SetClip (RectangleF rect) {
  1593. SetClip (rect, CombineMode.Replace);
  1594. }
  1595. public void SetClip (GraphicsPath path) {
  1596. SetClip (path, CombineMode.Replace);
  1597. }
  1598. public void SetClip (Rectangle rect) {
  1599. SetClip (rect, CombineMode.Replace);
  1600. }
  1601. public void SetClip (Graphics g) {
  1602. SetClip (g, CombineMode.Replace);
  1603. }
  1604. public void SetClip (Graphics g, CombineMode combineMode) {
  1605. if(g == null)
  1606. throw new NullReferenceException();
  1607. CombineClipArea(g._clip.NativeObject, combineMode);
  1608. }
  1609. public void SetClip (Rectangle rect, CombineMode combineMode) {
  1610. SetClip(rect.X,rect.Y,rect.Width,rect.Height,combineMode);
  1611. }
  1612. public void SetClip (RectangleF rect, CombineMode combineMode) {
  1613. SetClip(rect.X,rect.Y,rect.Width,rect.Height,combineMode);
  1614. }
  1615. public void SetClip (Region region, CombineMode combineMode) {
  1616. if(region == null)
  1617. throw new ArgumentNullException("region");
  1618. CombineClipArea ((geom.Area) region.NativeObject.MemberwiseClone (), combineMode);
  1619. }
  1620. public void SetClip (GraphicsPath path, CombineMode combineMode) {
  1621. if(path == null)
  1622. throw new ArgumentNullException("path");
  1623. CombineClipArea(new geom.Area(path.NativeObject), combineMode);
  1624. }
  1625. #endregion
  1626. #region Clipping Staff [INTERNAL]
  1627. internal Region ScaledClip {
  1628. get {
  1629. return _clip.Clone();
  1630. }
  1631. set {
  1632. _clip.NativeObject.reset();
  1633. _clip.NativeObject.add(value.NativeObject);
  1634. }
  1635. }
  1636. internal void SetClip(float x,float y,float width,float height,CombineMode combineMode) {
  1637. CombineClipArea(new geom.Area(
  1638. new geom.Rectangle2D.Float(x,y,width,height)),combineMode);
  1639. }
  1640. void CombineClipArea(geom.Area area, CombineMode combineMode) {
  1641. geom.AffineTransform t = GetFinalTransform();
  1642. if (!t.isIdentity())
  1643. area.transform(t);
  1644. if (combineMode == CombineMode.Replace) {
  1645. _clip.NativeObject.reset();
  1646. _clip.NativeObject.add(area);
  1647. }
  1648. else {
  1649. geom.Area curClip = _clip.NativeObject;
  1650. switch(combineMode) {
  1651. case CombineMode.Complement:
  1652. curClip.add(area);
  1653. break;
  1654. case CombineMode.Exclude:
  1655. curClip.subtract(area);
  1656. break;
  1657. case CombineMode.Intersect:
  1658. curClip.intersect(area);
  1659. break;
  1660. case CombineMode.Union:
  1661. curClip.add(area);
  1662. break;
  1663. case CombineMode.Xor:
  1664. curClip.exclusiveOr(area);
  1665. break;
  1666. default:
  1667. throw new ArgumentOutOfRangeException();
  1668. }
  1669. }
  1670. RestoreBaseClip();
  1671. NativeObject.clip(_clip);
  1672. }
  1673. internal void IntersectScaledClipWithBase(awt.Shape clip) {
  1674. NativeObject.clip(clip);
  1675. }
  1676. void RestoreBaseClip() {
  1677. if (_nextGraphicsState == null) {
  1678. NativeObject.setClip(_windowRect);
  1679. return;
  1680. }
  1681. _nextGraphicsState.RestoreBaseClip(this);
  1682. }
  1683. #endregion
  1684. #region TransformPoints
  1685. [MonoTODO]
  1686. public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, PointF [] pts) {
  1687. //TBD:CoordinateSpace
  1688. java.awt.geom.AffineTransform tr = this.Transform.NativeObject;
  1689. float[] fpts = new float[2];
  1690. for(int i = 0; i< pts.Length; i++) {
  1691. fpts[0] = pts[i].X;
  1692. fpts[1] = pts[i].Y;
  1693. tr.transform(fpts, 0, fpts, 0, 1);
  1694. pts[i].X = fpts[0];
  1695. pts[i].Y = fpts[1];
  1696. }
  1697. }
  1698. [MonoTODO]
  1699. public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, Point [] pts) {
  1700. //TBD:CoordinateSpace
  1701. java.awt.geom.AffineTransform tr = this.Transform.NativeObject;
  1702. float[] fpts = new float[2];
  1703. for(int i = 0; i< pts.Length; i++) {
  1704. fpts[0] = pts[i].X;
  1705. fpts[1] = pts[i].Y;
  1706. tr.transform(fpts, 0, fpts, 0, 1);
  1707. pts[i].X = (int)fpts[0];
  1708. pts[i].Y = (int)fpts[1];
  1709. }
  1710. }
  1711. #endregion
  1712. #region TranslateClip
  1713. public void TranslateClip (int dx, int dy) {
  1714. TranslateClip((float)dx, (float)dy);
  1715. }
  1716. public void TranslateClip (float dx, float dy) {
  1717. double x = dx;
  1718. double y = dy;
  1719. geom.AffineTransform f = GetFinalTransform();
  1720. if (!f.isIdentity()) {
  1721. double[] p = new double[] {x, y};
  1722. f.deltaTransform(p, 0, p, 0, 1);
  1723. x = p[0];
  1724. y = p[1];
  1725. }
  1726. // It seems .Net does exactly this...
  1727. x = Math.Floor(x+0.96875);
  1728. y = Math.Floor(y+0.96875);
  1729. geom.AffineTransform t = geom.AffineTransform.getTranslateInstance(x, y);
  1730. _clip.NativeObject.transform(t);
  1731. RestoreBaseClip();
  1732. NativeObject.clip(_clip);
  1733. }
  1734. #endregion
  1735. #region TranslateTransform
  1736. public void TranslateTransform (float dx, float dy) {
  1737. TranslateTransform (dx, dy, MatrixOrder.Prepend);
  1738. }
  1739. public void TranslateTransform (float dx, float dy, MatrixOrder order) {
  1740. ConcatenateTransform(
  1741. geom.AffineTransform.getTranslateInstance(dx, dy),
  1742. order);
  1743. }
  1744. #endregion
  1745. #region Properties [Partial TODO]
  1746. public Region Clip {
  1747. get {
  1748. Region r = _clip.Clone();
  1749. geom.AffineTransform t = GetFinalTransform();
  1750. if (!t.isIdentity())
  1751. r.NativeObject.transform(t.createInverse());
  1752. return r;
  1753. }
  1754. set {
  1755. SetClip (value, CombineMode.Replace);
  1756. }
  1757. }
  1758. public RectangleF ClipBounds {
  1759. get {
  1760. awt.Shape shape = _clip.NativeObject;
  1761. if (shape == null)
  1762. shape = Region.InfiniteRegion.NativeObject;
  1763. geom.RectangularShape r = shape.getBounds2D();
  1764. geom.AffineTransform t = GetFinalTransform();
  1765. if (!t.isIdentity()) {
  1766. geom.AffineTransform it = t.createInverse();
  1767. r = it.createTransformedShape(r).getBounds2D();
  1768. }
  1769. return new RectangleF (r);
  1770. }
  1771. }
  1772. public CompositingMode CompositingMode {
  1773. //TBD:check this carefully
  1774. get {
  1775. return (NativeObject.getComposite() == awt.AlphaComposite.SrcOver) ?
  1776. CompositingMode.SourceOver : CompositingMode.SourceCopy;
  1777. }
  1778. set {
  1779. NativeObject.setComposite(
  1780. (value == CompositingMode.SourceOver) ?
  1781. awt.AlphaComposite.SrcOver : awt.AlphaComposite.Src);
  1782. }
  1783. }
  1784. public CompositingQuality CompositingQuality {
  1785. get {
  1786. awt.RenderingHints hints = NativeObject.getRenderingHints();
  1787. if(hints.containsKey(awt.RenderingHints.KEY_ALPHA_INTERPOLATION)) {
  1788. object value_ai = hints.get(awt.RenderingHints.KEY_ALPHA_INTERPOLATION);
  1789. if (value_ai == awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)
  1790. return CompositingQuality.HighSpeed;
  1791. if (value_ai == awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)
  1792. return CompositingQuality.HighQuality;
  1793. if (value_ai == awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)
  1794. return CompositingQuality.Default;
  1795. }
  1796. return CompositingQuality.Default;
  1797. }
  1798. set {
  1799. awt.RenderingHints hints = NativeObject.getRenderingHints();
  1800. switch (value) {
  1801. case CompositingQuality.AssumeLinear:
  1802. case CompositingQuality.Default:
  1803. case CompositingQuality.GammaCorrected:
  1804. hints.put(awt.RenderingHints.KEY_ALPHA_INTERPOLATION,
  1805. awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT);
  1806. break;
  1807. case CompositingQuality.HighQuality:
  1808. hints.put(awt.RenderingHints.KEY_ALPHA_INTERPOLATION,
  1809. awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
  1810. break;
  1811. case CompositingQuality.HighSpeed:
  1812. hints.put(awt.RenderingHints.KEY_ALPHA_INTERPOLATION,
  1813. awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
  1814. break;
  1815. // case CompositingQuality.Invalid:
  1816. // if(hints.containsKey(awt.RenderingHints.KEY_ALPHA_INTERPOLATION))
  1817. // hints.remove(awt.RenderingHints.KEY_ALPHA_INTERPOLATION);
  1818. }
  1819. NativeObject.setRenderingHints(hints);
  1820. }
  1821. }
  1822. public float DpiX {
  1823. get {
  1824. return DefaultScreenResolution;
  1825. }
  1826. }
  1827. public float DpiY {
  1828. get {
  1829. //TBD: assume 72 (screen) for now
  1830. return DpiX;
  1831. }
  1832. }
  1833. public InterpolationMode InterpolationMode {
  1834. get {
  1835. awt.RenderingHints hints = NativeObject.getRenderingHints();
  1836. if(hints.containsKey(awt.RenderingHints.KEY_INTERPOLATION)) {
  1837. object value_i = hints.get(awt.RenderingHints.KEY_INTERPOLATION);
  1838. if (value_i == awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR)
  1839. return InterpolationMode.Bilinear;
  1840. if (value_i == awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC)
  1841. return InterpolationMode.Bicubic;
  1842. if (value_i == awt.RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)
  1843. return InterpolationMode.NearestNeighbor;
  1844. }
  1845. return InterpolationMode.Default;
  1846. }
  1847. set {
  1848. awt.RenderingHints hints = NativeObject.getRenderingHints();
  1849. switch (value) {
  1850. case InterpolationMode.Bicubic:
  1851. case InterpolationMode.HighQualityBicubic:
  1852. case InterpolationMode.Low:
  1853. hints.put(awt.RenderingHints.KEY_INTERPOLATION, awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC);
  1854. break;
  1855. case InterpolationMode.High:
  1856. case InterpolationMode.Bilinear:
  1857. case InterpolationMode.HighQualityBilinear:
  1858. hints.put(awt.RenderingHints.KEY_INTERPOLATION, awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  1859. break;
  1860. case InterpolationMode.Default:
  1861. if (hints.containsKey(awt.RenderingHints.KEY_INTERPOLATION))
  1862. hints.remove(awt.RenderingHints.KEY_INTERPOLATION);
  1863. break;
  1864. case InterpolationMode.NearestNeighbor:
  1865. hints.put(awt.RenderingHints.KEY_INTERPOLATION, awt.RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
  1866. break;
  1867. case InterpolationMode.Invalid:
  1868. throw new ArgumentException();
  1869. default:
  1870. throw new ArgumentOutOfRangeException();
  1871. }
  1872. NativeObject.setRenderingHints(hints);
  1873. }
  1874. }
  1875. public bool IsClipEmpty {
  1876. get {
  1877. return _clip.IsEmpty(this);
  1878. }
  1879. }
  1880. public bool IsVisibleClipEmpty {
  1881. get {
  1882. if (_clip.IsEmpty(this))
  1883. return true;
  1884. return VisibleClipBounds.IsEmpty;
  1885. }
  1886. }
  1887. public float PageScale {
  1888. get {
  1889. return _pageScale;
  1890. }
  1891. set {
  1892. _pageScale = value;
  1893. }
  1894. }
  1895. public GraphicsUnit PageUnit {
  1896. get {
  1897. return _pageUnit;
  1898. }
  1899. set {
  1900. _pageUnit = value;
  1901. }
  1902. }
  1903. static internal geom.AffineTransform GetFinalTransform(
  1904. geom.AffineTransform transform, GraphicsUnit pageUnit, float pageScale) {
  1905. geom.AffineTransform t = null;
  1906. if (pageUnit != GraphicsUnit.Display) {
  1907. float scale = pageScale * _unitConversion[ (int)pageUnit ];
  1908. if (Math.Abs(scale-1f) > float.Epsilon)
  1909. t = geom.AffineTransform.getScaleInstance(scale, scale);
  1910. }
  1911. if (t != null)
  1912. t.concatenate(transform);
  1913. else
  1914. t = transform;
  1915. return t;
  1916. }
  1917. geom.AffineTransform GetFinalTransform() {
  1918. return GetFinalTransform(_transform.NativeObject, PageUnit, PageScale);
  1919. }
  1920. public PixelOffsetMode PixelOffsetMode {
  1921. get {
  1922. return _pixelOffsetMode;
  1923. }
  1924. set {
  1925. _pixelOffsetMode = value;
  1926. }
  1927. }
  1928. [MonoTODO]
  1929. public Point RenderingOrigin {
  1930. get {
  1931. throw new NotImplementedException();
  1932. }
  1933. set {
  1934. throw new NotImplementedException();
  1935. }
  1936. }
  1937. public SmoothingMode SmoothingMode {
  1938. get {
  1939. awt.RenderingHints hints = NativeObject.getRenderingHints();
  1940. if(hints.containsKey(awt.RenderingHints.KEY_ANTIALIASING)) {
  1941. object value_aa = hints.get(awt.RenderingHints.KEY_ANTIALIASING);
  1942. if (value_aa == awt.RenderingHints.VALUE_ANTIALIAS_ON) {
  1943. if(hints.containsKey(awt.RenderingHints.KEY_RENDERING)) {
  1944. object value_render = hints.get(awt.RenderingHints.KEY_RENDERING);
  1945. if (value_render == awt.RenderingHints.VALUE_RENDER_QUALITY)
  1946. return SmoothingMode.HighQuality;
  1947. if (value_render == awt.RenderingHints.VALUE_RENDER_SPEED)
  1948. return SmoothingMode.HighSpeed;
  1949. }
  1950. return SmoothingMode.AntiAlias;
  1951. }
  1952. if (value_aa == awt.RenderingHints.VALUE_ANTIALIAS_DEFAULT)
  1953. return SmoothingMode.Default;
  1954. }
  1955. return SmoothingMode.None;
  1956. }
  1957. set {
  1958. awt.RenderingHints hints = NativeObject.getRenderingHints();
  1959. switch (value) {
  1960. case SmoothingMode.None:
  1961. if(hints.containsKey(awt.RenderingHints.KEY_ANTIALIASING))
  1962. hints.remove(awt.RenderingHints.KEY_ANTIALIASING);
  1963. if(hints.containsKey(awt.RenderingHints.KEY_RENDERING))
  1964. hints.remove(awt.RenderingHints.KEY_RENDERING);
  1965. break;
  1966. case SmoothingMode.AntiAlias:
  1967. hints.put(awt.RenderingHints.KEY_ANTIALIASING, awt.RenderingHints.VALUE_ANTIALIAS_ON);
  1968. break;
  1969. case SmoothingMode.HighQuality:
  1970. hints.put(awt.RenderingHints.KEY_RENDERING, awt.RenderingHints.VALUE_RENDER_QUALITY);
  1971. goto case SmoothingMode.AntiAlias;
  1972. case SmoothingMode.HighSpeed:
  1973. hints.put(awt.RenderingHints.KEY_RENDERING, awt.RenderingHints.VALUE_RENDER_SPEED);
  1974. goto case SmoothingMode.None;
  1975. case SmoothingMode.Default:
  1976. hints.put(awt.RenderingHints.KEY_RENDERING, awt.RenderingHints.VALUE_RENDER_DEFAULT);
  1977. goto case SmoothingMode.AntiAlias;
  1978. case SmoothingMode.Invalid:
  1979. throw new ArgumentException("Invalid parameter used.");
  1980. }
  1981. NativeObject.setRenderingHints(hints);
  1982. }
  1983. }
  1984. /// <summary>
  1985. /// Java does not have similar functionality
  1986. /// </summary>
  1987. public int TextContrast {
  1988. get {
  1989. return _textContrast;
  1990. }
  1991. set {
  1992. _textContrast = value;
  1993. }
  1994. }
  1995. public TextRenderingHint TextRenderingHint {
  1996. get {
  1997. return _textRenderingHint;
  1998. // awt.RenderingHints hints = NativeObject.getRenderingHints();
  1999. // if(hints.containsKey(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING)) {
  2000. // if(hints.get(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING) ==
  2001. // java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON)
  2002. // return TextRenderingHint.AntiAlias;
  2003. // if(hints.get(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING) ==
  2004. // java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
  2005. // return TextRenderingHint.SingleBitPerPixel;
  2006. // }
  2007. // //return TextRenderingHint.SystemDefault;
  2008. // return TextRenderingHint.SingleBitPerPixelGridFit;
  2009. }
  2010. set {
  2011. _textRenderingHint = value;
  2012. awt.RenderingHints hints = NativeObject.getRenderingHints();
  2013. switch (value) {
  2014. case TextRenderingHint.AntiAlias:
  2015. case TextRenderingHint.AntiAliasGridFit:
  2016. case TextRenderingHint.ClearTypeGridFit:
  2017. // case TextRenderingHint.SystemDefault:
  2018. hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
  2019. awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
  2020. break;
  2021. case TextRenderingHint.SingleBitPerPixelGridFit:
  2022. hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
  2023. awt.RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
  2024. break;
  2025. case TextRenderingHint.SingleBitPerPixel:
  2026. hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
  2027. awt.RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
  2028. break;
  2029. case TextRenderingHint.SystemDefault:
  2030. hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
  2031. awt.RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
  2032. break;
  2033. }
  2034. NativeObject.setRenderingHints(hints);
  2035. }
  2036. }
  2037. public Matrix Transform {
  2038. get {
  2039. return _transform.Clone();
  2040. }
  2041. set {
  2042. if (value == null)
  2043. throw new ArgumentNullException("matrix");
  2044. if (!value.IsInvertible)
  2045. throw new ArgumentException("Invalid parameter used.");
  2046. value.CopyTo(_transform);
  2047. }
  2048. }
  2049. internal Matrix BaseTransform {
  2050. get {
  2051. return new Matrix(NativeObject.getTransform());
  2052. }
  2053. set {
  2054. NativeObject.setTransform(value.NativeObject);
  2055. }
  2056. }
  2057. internal void PrependBaseTransform(geom.AffineTransform t) {
  2058. NativeObject.transform(t);
  2059. }
  2060. internal awt.Shape VisibleShape {
  2061. get {
  2062. return _windowRect;
  2063. }
  2064. }
  2065. public RectangleF VisibleClipBounds {
  2066. get {
  2067. if (_clip.IsEmpty(this))
  2068. return RectangleF.Empty;
  2069. geom.Rectangle2D r = _clip.NativeObject.getBounds2D();
  2070. awt.Shape clip = NativeObject.getClip();
  2071. geom.Rectangle2D clipBounds = (clip != null) ? clip.getBounds2D() : _windowRect;
  2072. geom.Rectangle2D.intersect(r, clipBounds, r);
  2073. if ((r.getWidth() <= 0) || (r.getHeight() <= 0))
  2074. return RectangleF.Empty;
  2075. geom.AffineTransform t = GetFinalTransform();
  2076. if (!t.isIdentity()) {
  2077. geom.AffineTransform it = t.createInverse();
  2078. r = it.createTransformedShape(r).getBounds2D();
  2079. }
  2080. return new RectangleF (r);
  2081. }
  2082. }
  2083. void ConcatenateTransform(geom.AffineTransform transform, MatrixOrder order) {
  2084. geom.AffineTransform at = _transform.NativeObject;
  2085. Matrix.Multiply(at, transform, order);
  2086. }
  2087. #endregion
  2088. }
  2089. }