| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564 |
- using System;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.Drawing.Text;
- using System.ComponentModel;
- using System.Collections;
- using System.Runtime.InteropServices;
- using System.Text;
- using awt = java.awt;
- using geom = java.awt.geom;
- namespace System.Drawing {
- [ComVisible(false)]
- public sealed class Graphics : MarshalByRefObject, IDisposable {
- sealed class DummyStroke : awt.Stroke {
- #region Stroke Members
- awt.Shape awt.Stroke.createStrokedShape(awt.Shape arg_0) {
- throw new NotImplementedException("DummyStroke");
- }
- #endregion
- }
- sealed class NormalizingPathIterator : geom.PathIterator {
- #region fields
- readonly geom.PathIterator _iter;
- const float norm = 0.5f;
- const float rnd = (1.0f - norm);
- float ax = 0.0f;
- float ay = 0.0f;
- #endregion
- #region ctor
- public NormalizingPathIterator(geom.PathIterator iter) {
- _iter = iter;
- }
- #endregion
- #region methods
- static int GetIndex(int type) {
- int index;
- switch ((GraphicsPath.JPI)type) {
- case GraphicsPath.JPI.SEG_CUBICTO:
- index = 4;
- break;
- case GraphicsPath.JPI.SEG_QUADTO:
- index = 2;
- break;
- case GraphicsPath.JPI.SEG_MOVETO:
- case GraphicsPath.JPI.SEG_LINETO:
- index = 0;
- break;
- case GraphicsPath.JPI.SEG_CLOSE:
- default:
- index = -1;
- break;
- }
- return index;
- }
- #endregion
- #region PathIterator Members
- void geom.PathIterator.next() {
- _iter.next();
- }
- bool geom.PathIterator.isDone() {
- return _iter.isDone();
- }
- int geom.PathIterator.currentSegment(float[] point) {
- int type = _iter.currentSegment(point);
- int index = GetIndex(type);
-
- if (index >= 0) {
- float ox = point[index];
- float oy = point[index+1];
- float newax = (float) java.lang.Math.floor(ox + rnd) + norm;
- float neway = (float) java.lang.Math.floor(oy + rnd) + norm;
- point[index] = newax;
- point[index+1] = neway;
- newax -= ox;
- neway -= oy;
- switch ((GraphicsPath.JPI)type) {
- case GraphicsPath.JPI.SEG_CUBICTO:
- point[0] += ax;
- point[1] += ay;
- point[2] += newax;
- point[3] += neway;
- break;
- case GraphicsPath.JPI.SEG_QUADTO:
- point[0] += (newax + ax) / 2;
- point[1] += (neway + ay) / 2;
- break;
- // case GraphicsPath.JPI.SEG_MOVETO:
- // case GraphicsPath.JPI.SEG_LINETO:
- // case GraphicsPath.JPI.SEG_CLOSE:
- // break;
- }
- ax = newax;
- ay = neway;
- }
- return type;
- }
- int geom.PathIterator.currentSegment(double[] point) {
- int type = _iter.currentSegment(point);
- int index = GetIndex(type);
- if (index >= 0) {
- float ox = (float)point[index];
- float oy = (float)point[index+1];
- float newax = (float)java.lang.Math.floor(ox + rnd) + norm;
- float neway = (float)java.lang.Math.floor(oy + rnd) + norm;
- point[index] = newax;
- point[index+1] = neway;
- newax -= ox;
- neway -= oy;
- switch ((GraphicsPath.JPI)type) {
- case GraphicsPath.JPI.SEG_CUBICTO:
- point[0] += ax;
- point[1] += ay;
- point[2] += newax;
- point[3] += neway;
- break;
- case GraphicsPath.JPI.SEG_QUADTO:
- point[0] += (newax + ax) / 2;
- point[1] += (neway + ay) / 2;
- break;
- // case GraphicsPath.JPI.SEG_MOVETO:
- // case GraphicsPath.JPI.SEG_LINETO:
- // case GraphicsPath.JPI.SEG_CLOSE:
- // break;
- }
- ax = newax;
- ay = neway;
- }
- return type;
- }
- int geom.PathIterator.getWindingRule() {
- return _iter.getWindingRule();
- }
- #endregion
- }
- #region Variables
- readonly awt.Graphics2D _nativeObject;
- PixelOffsetMode _pixelOffsetMode = PixelOffsetMode.Default;
- int _textContrast = 4;
- TextRenderingHint _textRenderingHint;
- readonly Image _image;
-
- readonly Matrix _transform;
- GraphicsUnit _pageUnit = GraphicsUnit.Display;
- float _pageScale = 1.0f;
- readonly Region _clip;
- readonly awt.Rectangle _windowRect;
- GraphicsState _nextGraphicsState = null;
- static readonly float [] _unitConversion = {
- 1, // World
- 1, // Display
- 1, // Pixel
- DefaultScreenResolution / 72.0f, // Point
- DefaultScreenResolution, // Inch
- DefaultScreenResolution / 300.0f,// Document
- DefaultScreenResolution / 25.4f // Millimeter
- };
- static int _isHeadless;
- static internal bool IsHeadless {
- get {
- if (_isHeadless == 0) {
- bool isHeadless = awt.GraphicsEnvironment.isHeadless();
- if (!isHeadless) {
- try {
- awt.Toolkit.getDefaultToolkit();
- }
- catch{
- isHeadless = true;
- }
- }
- _isHeadless = isHeadless ? 2 : 1;
- }
- return _isHeadless > 1;
- }
- }
-
- #endregion
- #if INTPTR_SUPPORT
- [ComVisible(false)]
- public delegate bool EnumerateMetafileProc (EmfPlusRecordType recordType,
- int flags,
- int dataSize,
- IntPtr data,
- PlayRecordCallback callbackData);
- [ComVisible (false)]
- public delegate bool DrawImageAbort (IntPtr callbackData);
- #endif
- #region Constr. and Destr.
- private Graphics (Image image) {
- _nativeObject = (awt.Graphics2D)image.NativeObject.CurrentImage.NativeImage.getGraphics();
- _image = image;
- _transform = new Matrix ();
- NativeObject.setStroke(new DummyStroke());
- NativeObject.setRenderingHint(awt.RenderingHints.KEY_COLOR_RENDERING, awt.RenderingHints.VALUE_COLOR_RENDER_QUALITY);
- InterpolationMode = InterpolationMode.Bilinear;
- TextRenderingHint = TextRenderingHint.SystemDefault;
- _windowRect = new awt.Rectangle(_image.Width, _image.Height);
- _clip = new Region();
- }
- #endregion
-
- #region Internal Accessors
- static internal float [] UnitConversion {
- get {
- return _unitConversion;
- }
- }
-
- static internal int DefaultScreenResolution {
- get {
- return IsHeadless ? 96 :
- awt.Toolkit.getDefaultToolkit().getScreenResolution();
- }
- }
-
- internal java.awt.Graphics2D NativeObject {
- get {
- return _nativeObject;
- }
- }
- #endregion
- #region FromImage (static accessor)
- public static Graphics FromImage (Image image) {
- return new Graphics(image);
- }
- #endregion
- #region Workers [INTERNAL]
- void DrawShape(Pen pen, awt.Shape shape) {
- if (pen == null)
- throw new ArgumentNullException("pen");
- if (StrokeFactory.CanCreateAdvancedStroke &&
- (!pen.CanCreateBasicStroke || !NeedsNormalization)) {
- geom.AffineTransform oldT = NativeObject.getTransform();
- NativeObject.setTransform(Matrix.IdentityTransform.NativeObject);
- try {
- geom.AffineTransform t = GetFinalTransform();
- if (!oldT.isIdentity()) {
- t = (geom.AffineTransform)t.MemberwiseClone();
- t.preConcatenate(oldT);
- }
-
- double widthsquared = pen.GetSquaredTransformedWidth(t);
- bool antiAlias = (SmoothingMode == SmoothingMode.AntiAlias);
- bool thin = (widthsquared <= (antiAlias ?
- AdvancedStroke.MinPenSizeAASquared :
- AdvancedStroke.MinPenSizeSquared));
- PenFit penFit = thin ? (antiAlias ? PenFit.ThinAntiAlias : PenFit.Thin) : PenFit.NotThin;
- if (NeedsNormalization) {
- bool normThin =
- widthsquared <= AdvancedStroke.MinPenSizeSquaredNorm;
- if (normThin) {
- shape = GetNormalizedShape(shape, t);
- shape = pen.GetNativeObject(
- t, null, penFit).createStrokedShape(shape);
- }
- else {
- shape = pen.GetNativeObject(t, penFit).createStrokedShape(shape);
- shape = GetNormalizedShape(shape, null);
- }
- }
- else {
- shape = pen.GetNativeObject(t, penFit).createStrokedShape(shape);
- }
- FillScaledShape(pen.Brush, shape);
- }
- finally {
- NativeObject.setTransform(oldT);
- }
- }
- else {
- awt.Stroke oldStroke = NativeObject.getStroke();
- NativeObject.setStroke(pen.GetNativeObject(null, PenFit.NotThin));
- try {
- NativeObject.setPaint(pen.Brush);
- geom.AffineTransform oldT = NativeObject.getTransform();
- NativeObject.transform(GetFinalTransform());
- try {
- NativeObject.draw(shape);
- }
- finally {
- NativeObject.setTransform(oldT);
- }
- }
- finally {
- NativeObject.setStroke(oldStroke);
- }
- }
- }
- void FillShape(Brush paint, awt.Shape shape) {
- if (paint == null)
- throw new ArgumentNullException("brush");
- geom.AffineTransform oldT = null;
- if (NeedsNormalization) {
- oldT = NativeObject.getTransform();
- geom.AffineTransform t = GetFinalTransform();
- if (!oldT.isIdentity()) {
- t = (geom.AffineTransform) t.MemberwiseClone ();
- t.preConcatenate(oldT);
- }
- shape = GetNormalizedShape(shape, t);
- }
- else {
- geom.AffineTransform t = GetFinalTransform();
- if (!t.isIdentity())
- shape = t.createTransformedShape(shape);
- }
- if (oldT != null)
- NativeObject.setTransform(Matrix.IdentityTransform.NativeObject);
- try {
- FillScaledShape(paint, shape);
- }
- finally {
- if (oldT != null)
- NativeObject.setTransform(oldT);
- }
- }
- bool NeedsNormalization {
- get {
- return PixelOffsetMode != PixelOffsetMode.Half &&
- PixelOffsetMode != PixelOffsetMode.HighQuality;
- }
- }
- static awt.Shape GetNormalizedShape(awt.Shape shape, geom.AffineTransform t) {
- geom.PathIterator iter = new NormalizingPathIterator(shape.getPathIterator(t));
-
- geom.GeneralPath path = new geom.GeneralPath(iter.getWindingRule());
- path.append(iter, false);
- return path;
- }
- void FillScaledShape(Brush paint, awt.Shape shape) {
- Matrix m = null;
- if (!(paint is SolidBrush || paint is HatchBrush) && !_transform.IsIdentity) {
- m = paint.BrushTransform;
- paint.BrushMultiplyTransform( _transform );
- }
- try {
- NativeObject.setPaint(paint);
- NativeObject.fill(shape);
- }
- finally {
- if (m != null)
- paint.BrushTransform = m;
- }
- }
- #endregion
- #region Dispose
- public void Dispose() {
- NativeObject.dispose();
- }
- #endregion
-
- #region Clear
- public void Clear (Color color) {
- FillScaledShape(new SolidBrush( color ), _clip.NativeObject);
- }
- #endregion
- #region DrawArc
- public void DrawArc (Pen pen, Rectangle rect, float startAngle, float sweepAngle) {
- DrawArc (pen,
- rect.X,
- rect.Y,
- rect.Width,
- rect.Height,
- startAngle,
- sweepAngle);
- }
-
- public void DrawArc (Pen pen, RectangleF rect, float startAngle, float sweepAngle) {
- DrawArc (pen,
- rect.X,
- rect.Y,
- rect.Width,
- rect.Height,
- startAngle,
- sweepAngle);
- }
- public void DrawArc (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle) {
- DrawArc(pen,
- (float)x,
- (float)y,
- (float)width,
- (float)height,
- (float)startAngle,
- (float)sweepAngle);
- }
- public void DrawArc (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) {
- GraphicsPath path = new GraphicsPath();
- path.AddArc(x, y, width, height, startAngle, sweepAngle);
- DrawPath(pen, path);
- }
- #endregion
- #region DrawBezier(s)
- public void DrawBezier (Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4) {
- DrawBezier(pen, pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
- }
- public void DrawBezier (Pen pen, Point pt1, Point pt2, Point pt3, Point pt4) {
- DrawBezier(pen, pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X, pt3.Y, pt4.X, pt4.Y);
- }
- public void DrawBezier (Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
- geom.GeneralPath path = new geom.GeneralPath();
- path.moveTo(x1,y1);
- path.curveTo(x2,y2,x3,y3,x4,y4);
- DrawShape(pen, path);
- }
- public void DrawBeziers (Pen pen, Point [] points) {
- GraphicsPath path = new GraphicsPath();
- path.AddBeziers(points);
- DrawPath(pen, path);
- }
- public void DrawBeziers (Pen pen, PointF [] points) {
- GraphicsPath path = new GraphicsPath();
- path.AddBeziers(points);
- DrawPath(pen, path);
- }
- #endregion
- #region DrawClosedCurve
- public void DrawClosedCurve (Pen pen, PointF [] points) {
- DrawClosedCurve(pen, points, 0.5f, FillMode.Alternate);
- }
-
- public void DrawClosedCurve (Pen pen, Point [] points) {
- DrawClosedCurve(pen, points, 0.5f, FillMode.Alternate);
- }
-
- public void DrawClosedCurve (Pen pen, Point [] points, float tension, FillMode fillmode) {
- GraphicsPath path = new GraphicsPath(fillmode);
- path.AddClosedCurve(points, tension);
- DrawPath(pen, path);
- }
-
- public void DrawClosedCurve (Pen pen, PointF [] points, float tension, FillMode fillmode) {
- GraphicsPath path = new GraphicsPath(fillmode);
- path.AddClosedCurve(points, tension);
- DrawPath(pen, path);
- }
- #endregion
- #region DrawCurve
- public void DrawCurve (Pen pen, Point [] points) {
- DrawCurve(pen, points, 0.5f);
- }
-
- public void DrawCurve (Pen pen, PointF [] points) {
- DrawCurve(pen, points, 0.5f);
- }
-
- public void DrawCurve (Pen pen, PointF [] points, float tension) {
- DrawCurve(pen, points, 0, points.Length-1, tension);
- }
-
- public void DrawCurve (Pen pen, Point [] points, float tension) {
- DrawCurve(pen, points, 0, points.Length-1, tension);
- }
-
-
- public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments) {
- DrawCurve(pen, points, offset, numberOfSegments, 0.5f);
- }
- public void DrawCurve (Pen pen, Point [] points, int offset, int numberOfSegments, float tension) {
- GraphicsPath path = new GraphicsPath();
- path.AddCurve(points, offset, numberOfSegments, tension);
- DrawPath(pen, path);
- }
-
- public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments, float tension) {
- GraphicsPath path = new GraphicsPath();
- path.AddCurve(points, offset, numberOfSegments, tension);
- DrawPath(pen, path);
- }
- #endregion
- #region DrawEllipse
- public void DrawEllipse (Pen pen, Rectangle rect) {
- DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
- }
- public void DrawEllipse (Pen pen, RectangleF rect) {
- DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
- }
- public void DrawEllipse (Pen pen, int x, int y, int width, int height) {
- DrawEllipse(pen,(float)x,(float)y,(float)width,(float)height);
- }
- public void DrawEllipse (Pen pen, float x, float y, float width, float height) {
- DrawShape(pen, new geom.Ellipse2D.Float(x,y,width,height));
- }
- #endregion
- #region DrawIcon
- public void DrawIcon (Icon icon, Rectangle targetRect) {
- Bitmap b = icon.ToBitmap ();
- this.DrawImage (b, targetRect);
- }
- public void DrawIcon (Icon icon, int x, int y) {
- Bitmap b = icon.ToBitmap ();
- this.DrawImage (b, x, y);
- }
- public void DrawIconUnstretched (Icon icon, Rectangle targetRect) {
- Bitmap b = icon.ToBitmap ();
- this.DrawImageUnscaled (b, targetRect);
- }
- #endregion
- #region DrawImage
- public void DrawImage (Image image, Point point) {
- DrawImage(image, point.X, point.Y);
- }
- public void DrawImage (Image image, PointF point) {
- DrawImage(image, point.X, point.Y);
- }
-
- public void DrawImage (Image image, Point [] destPoints) {
- Matrix m = new Matrix(new Rectangle(0, 0, image.Width, image.Height), destPoints);
- DrawImage(image, m);
- }
- public void DrawImage (Image image, PointF [] destPoints) {
- Matrix m = new Matrix(new RectangleF(0, 0, image.Width, image.Height), destPoints);
- DrawImage(image, m);
- }
-
- public void DrawImage (Image image, Rectangle rect) {
- DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
- }
- public void DrawImage (Image image, RectangleF rect) {
- DrawImage(image, rect.X, rect.Y, rect.Width, rect.Height);
- }
-
- public void DrawImage (Image image, int x, int y) {
- DrawImage(image, (float)x, (float)y);
- }
- public void DrawImage (Image image, float x, float y) {
- if ((image.HorizontalResolution != DpiX) || (image.VerticalResolution != DpiY))
- DrawImage( image, x, y,
- (float)image.Width * (DpiX / image.HorizontalResolution) / _unitConversion[(int)PageUnit],
- (float)image.Height * (DpiY / image.VerticalResolution) / _unitConversion[(int)PageUnit]) ;
- else
- DrawImage( image, x, y,
- (float)image.Width / _unitConversion[(int)PageUnit],
- (float)image.Height / _unitConversion[(int)PageUnit] );
- }
-
- public void DrawImage (Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit) {
- DrawImage(
- image,
- new Point [] {
- new Point( destRect.X, destRect.Y),
- new Point( destRect.X + destRect.Width, destRect.Y),
- new Point( destRect.X, destRect.Y + destRect.Height)},
- srcRect,
- srcUnit);
- }
-
- public void DrawImage (Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit) {
- DrawImage(
- image,
- new PointF [] {
- new PointF( destRect.X, destRect.Y),
- new PointF( destRect.X + destRect.Width, destRect.Y),
- new PointF( destRect.X, destRect.Y + destRect.Height)},
- srcRect,
- srcUnit);
- }
-
- public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit) {
- DrawImage(image, destPoints, srcRect, srcUnit, null);
- }
- public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit) {
- DrawImage(image, destPoints, srcRect, srcUnit, null);
- }
- [MonoTODO]
- public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr) {
- //TBD: ImageAttributes
- if (srcUnit != GraphicsUnit.Pixel)
- throw new NotImplementedException();
- // Like in .NET http://dotnet247.com/247reference/msgs/45/227979.aspx
- Matrix mx = new Matrix(srcRect, destPoints);
- Region region = new Region(srcRect);
- DrawImage(image, mx, region);
- }
-
- [MonoTODO]
- public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr) {
- //TBD: ImageAttributes
- if (srcUnit != GraphicsUnit.Pixel)
- throw new NotImplementedException();
- // Like in .NET http://dotnet247.com/247reference/msgs/45/227979.aspx
- Matrix mx = new Matrix(srcRect, destPoints);
- Region region = new Region(srcRect);
- DrawImage(image, mx, region);
- }
- public void DrawImage (Image image, int x, int y, int width, int height) {
- DrawImage(image, (float)x, (float)y, (float)width, (float)height);
- }
- public void DrawImage (Image image, float x, float y, float width, float height) {
- Matrix mx = new Matrix();
- mx.Translate((float)x, (float)y);
- mx.Scale(width / (float)image.Width, height / (float)image.Height);
- DrawImage( image, mx );
- }
-
- public void DrawImage (Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit) {
- DrawImage(image, new Rectangle(x, y, srcRect.Width, srcRect.Height), srcRect, srcUnit);
- }
-
- public void DrawImage (Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit) {
- DrawImage(image, new RectangleF(x, y, srcRect.Width, srcRect.Height), srcRect, srcUnit);
- }
- public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit) {
- DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, null);
- }
- public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit) {
- DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, null);
- }
-
- [MonoTODO]
- public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr) {
- //TBD: attributes
- DrawImage(
- image,
- destRect,
- new Rectangle(srcX, srcY, srcWidth, srcHeight),
- srcUnit);
- }
-
- [MonoTODO]
- public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs) {
- //TBD: attributes
- DrawImage(
- image,
- destRect,
- new RectangleF(srcX, srcY, srcWidth, srcHeight),
- srcUnit);
- }
-
- internal void DrawImage (Image image, Matrix m) {
- DrawImage(image, m, null);
- }
- internal void DrawImage (Image image, Matrix m, Region clip) {
- if (clip == null) {
- clip = new Region( new RectangleF( 0, 0, image.Width, image.Height ) );
- }
- geom.AffineTransform t = GetFinalTransform(_transform.NativeObject, PageUnit, 1.0f);
- if (!t.isIdentity())
- m.NativeObject.preConcatenate(t);
- clip.Transform( m );
- if (NeedsNormalization) {
- Matrix normMatrix = ComputeClipNormalization(clip.GetBounds(this));
- clip.Transform(normMatrix);
- }
- awt.Shape oldClip = NativeObject.getClip();
- IntersectScaledClipWithBase(clip);
-
- try {
- Matrix mm = ComputeImageNormalization(image, m);
- NativeObject.drawImage(image.NativeObject.CurrentImage.NativeImage, mm.NativeObject, null);
- }
- finally {
- NativeObject.setClip( oldClip );
- }
- }
- private static Matrix ComputeImageNormalization(Image img, Matrix m) {
- if ( m.IsIdentity )
- return m;
- //m.Translate( -(m.Elements[0] + m.Elements[2]) / 2.0f, -(m.Elements[3] + m.Elements[1]) / 2.0f, MatrixOrder.Append);
- m.Translate(
- -(float)(m.NativeObject.getScaleX() + m.NativeObject.getShearX()) / 2.0f,
- -(float)(m.NativeObject.getScaleY() + m.NativeObject.getShearY()) / 2.0f, MatrixOrder.Append);
-
- PointF [] p = new PointF[] {
- new PointF( 0, 0 ),
- new PointF( img.Width, 0 ),
- new PointF( 0, img.Height )};
- m.TransformPoints(p);
- for (int i=0; i < p.Length; i++) {
- p[i].X = (float)( p[i].X + 0.5f );
- p[i].Y = (float)( p[i].Y + 0.5f );
- }
- return new Matrix( new Rectangle(0, 0, img.Width, img.Height), p );
- }
- private static Matrix ComputeClipNormalization(RectangleF rect) {
- PointF [] p = new PointF[] {
- new PointF( rect.X, rect.Y ),
- new PointF( rect.X + rect.Width, rect.Y ),
- new PointF( rect.X, rect.Y + rect.Height )};
- for (int i=0; i < p.Length; i++) {
- p[i].X = (float)Math.Round( p[i].X + 0.5f ) + 0.5f;
- p[i].Y = (float)Math.Round( p[i].Y + 0.5f ) + 0.5f;
- }
- return new Matrix( rect, p );
- }
-
- #if INTPTR_SUPPORT
- [MonoTODO]
- public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
- {
- throw new NotImplementedException();
- }
- [MonoTODO]
- public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
- {
-
- throw new NotImplementedException();
- }
- [MonoTODO]
- public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
- {
- throw new NotImplementedException();
- }
- #endif
- #if INTPTR_SUPPORT
- [MonoTODO]
- public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
- {
- throw new NotImplementedException();
- }
- #endif
- #if INTPTR_SUPPORT
- public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
- {
- //TBD:units,attributes, callback
- java.awt.Graphics2D g = (java.awt.Graphics2D)nativeObject;
- g.drawImage(image.NativeObject,destRect.X,destRect.Y,destRect.Width,destRect.Height,srcX,srcY,srcWidth,srcHeight,null);
- }
-
- public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
- {
- //TBD:units,attributes, callback
- java.awt.Graphics2D g = (java.awt.Graphics2D)nativeObject;
- g.drawImage(image.NativeObject,
- (int)destRect.X,
- (int)destRect.Y,
- (int)destRect.Width,
- (int)destRect.Height,
- (int)srcX,
- (int)srcY,
- (int)srcWidth,
- (int)srcHeight,null);
- }
- public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
- {
- //TBD:units,attributes, callback
- java.awt.Graphics2D g = (java.awt.Graphics2D)nativeObject;
- g.drawImage(image.NativeObject,
- (int)destRect.X,
- (int)destRect.Y,
- (int)destRect.Width,
- (int)destRect.Height,
- (int)srcX,
- (int)srcY,
- (int)srcWidth,
- (int)srcHeight,null);
- }
-
- public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
- {
- //TBD:units,attributes, callback
- java.awt.Graphics2D g = (java.awt.Graphics2D)nativeObject;
- g.drawImage(image.NativeObject,
- destRect.X,
- destRect.Y,
- destRect.Width,
- destRect.Height,
- srcX,
- srcY,
- srcWidth,
- srcHeight,null);
- }
- #endif
-
- public void DrawImageUnscaled (Image image, Point point)
- {
- DrawImageUnscaled (image, point.X, point.Y);
- }
-
- public void DrawImageUnscaled (Image image, Rectangle rect) {
- DrawImageUnscaled (image, rect.X, rect.Y, rect.Width, rect.Height);
- }
-
- public void DrawImageUnscaled (Image image, int x, int y) {
- DrawImage (image, x, y, image.Width, image.Height);
- }
- public void DrawImageUnscaled (Image image, int x, int y, int width, int height) {
- Image tmpImg = new Bitmap (width, height);
- Graphics g = FromImage (tmpImg);
- g.DrawImage (image, 0, 0, image.Width, image.Height);
- this.DrawImage (tmpImg, x, y, width, height);
- tmpImg.Dispose ();
- g.Dispose ();
- }
- #endregion
- #region DrawLine
- public void DrawLine (Pen pen, PointF pt1, PointF pt2) {
- DrawLine(pen,pt1.X,pt1.Y,pt2.X,pt2.Y);
- }
- public void DrawLine (Pen pen, Point pt1, Point pt2) {
- DrawLine(pen,(float)pt1.X,(float)pt1.Y,(float)pt2.X,(float)pt2.Y);
- }
- public void DrawLine (Pen pen, int x1, int y1, int x2, int y2) {
- DrawLine(pen,(float)x1,(float)y1,(float)x2,(float)y2);
- }
- public void DrawLine (Pen pen, float x1, float y1, float x2, float y2) {
- DrawShape(pen, new geom.Line2D.Float(x1,y1,x2,y2));
- }
- public void DrawLines (Pen pen, PointF [] points) {
- GraphicsPath path = new GraphicsPath();
- path.AddLines(points);
- DrawShape(pen, path);
- }
- public void DrawLines (Pen pen, Point [] points) {
- GraphicsPath path = new GraphicsPath();
- path.AddLines(points);
- DrawShape(pen, path);
- }
- #endregion
- #region DrawPath
- public void DrawPath (Pen pen, GraphicsPath path) {
- DrawShape(pen, path);
- }
- #endregion
-
- #region DrawPie
- public void DrawPie (Pen pen, Rectangle rect, float startAngle, float sweepAngle) {
- DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
- }
-
- public void DrawPie (Pen pen, RectangleF rect, float startAngle, float sweepAngle) {
- DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
- }
-
- public void DrawPie (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle) {
- GraphicsPath path = new GraphicsPath();
- path.AddPie(x, y, width, height, startAngle, sweepAngle);
- DrawPath(pen, path);
- }
-
- public void DrawPie (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle) {
- DrawPie(pen,(float)x,(float)y,(float)width,(float)height,(float)startAngle,(float)sweepAngle);
- }
- #endregion
- #region DrawPolygon
- public void DrawPolygon (Pen pen, Point [] points) {
- GraphicsPath path = new GraphicsPath();
- path.AddPolygon(points);
- DrawPath(pen, path);
- }
- public void DrawPolygon (Pen pen, PointF [] points) {
- GraphicsPath path = new GraphicsPath();
- path.AddPolygon(points);
- DrawPath(pen, path);
- }
- #endregion
- #region DrawRectangle(s)
- internal void DrawRectangle (Pen pen, RectangleF rect) {
- DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
- }
- public void DrawRectangle (Pen pen, Rectangle rect) {
- DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
- }
- public void DrawRectangle (Pen pen, float x, float y, float width, float height) {
- DrawShape(pen, new geom.Rectangle2D.Float(x,y,width,height));
- }
- public void DrawRectangle (Pen pen, int x, int y, int width, int height) {
- DrawRectangle (pen,(float) x,(float) y,(float) width,(float) height);
- }
- public void DrawRectangles (Pen pen, RectangleF [] rects) {
- foreach(RectangleF r in rects)
- DrawRectangle (pen, r.Left, r.Top, r.Width, r.Height);
- }
- public void DrawRectangles (Pen pen, Rectangle [] rects) {
- foreach(Rectangle r in rects)
- DrawRectangle (pen, r.Left, r.Top, r.Width, r.Height);
- }
- #endregion
- #region DrawString
- public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle) {
- DrawString(s, font, brush, layoutRectangle.X, layoutRectangle.Y, layoutRectangle.Width, layoutRectangle.Height, null);
- }
-
- public void DrawString (string s, Font font, Brush brush, PointF point) {
- DrawString(s, font, brush, point.X, point.Y, float.PositiveInfinity, float.PositiveInfinity, null);
- }
-
- public void DrawString (string s, Font font, Brush brush, PointF point, StringFormat format) {
- DrawString(s, font, brush, point.X, point.Y, float.PositiveInfinity, float.PositiveInfinity, format);
- }
- public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) {
- DrawString(s, font, brush, layoutRectangle.X, layoutRectangle.Y, layoutRectangle.Width, layoutRectangle.Height, format);
- }
- public void DrawString (string s, Font font, Brush brush, float x, float y) {
- DrawString(s, font, brush, x, y, float.PositiveInfinity, float.PositiveInfinity, null);
- }
- public void DrawString (string s, Font font, Brush brush, float x, float y, StringFormat format) {
- DrawString(s, font, brush, x, y, float.PositiveInfinity, float.PositiveInfinity, format);
- }
- void DrawString (string s, Font font, Brush brush,
- float x, float y, float width, float height,
- StringFormat format) {
- if (brush == null)
- throw new ArgumentNullException("brush");
- if (font == null)
- throw new ArgumentNullException("font");
- if (format != null && format.LineAlignment != StringAlignment.Near) {
- SizeF sizeF = MeasureString(s, font, format, width, height, null);
- float lineAWidth = width;
- float lineAHeight = height;
- if (float.IsPositiveInfinity(width))
- lineAWidth = lineAHeight = 0;
- float wdelta = format.IsVertical ? lineAWidth - sizeF.Width : lineAHeight - sizeF.Height;
- float pdelta = format.LineAlignment == StringAlignment.Center ? wdelta/2 : wdelta;
- if (format.IsVertical) {
- if (!(format.IsRightToLeft && format.LineAlignment == StringAlignment.Far))
- x += pdelta;
- if (!float.IsPositiveInfinity(width))
- width -= wdelta;
- }
- else {
- y += pdelta;
- if (!float.IsPositiveInfinity(width))
- height -= wdelta;
- }
- }
- awt.Paint oldP = NativeObject.getPaint();
- NativeObject.setPaint(brush);
- try {
- geom.AffineTransform oldT = NativeObject.getTransform();
- NativeObject.transform(GetFinalTransform());
- try {
- bool noclip = float.IsPositiveInfinity(width) || (format != null && format.NoClip);
- awt.Shape oldClip = null;
- if (!noclip) {
- oldClip = NativeObject.getClip();
- NativeObject.clip(new geom.Rectangle2D.Float(x, y, width, height));
- }
- try {
- TextLineIterator iter = new TextLineIterator(s, font, NativeObject.getFontRenderContext(), format, width, height);
- NativeObject.transform(iter.Transform);
- for (LineLayout layout = iter.NextLine(); layout != null; layout = iter.NextLine()) {
- layout.Draw(NativeObject, x, y);
- }
- }
- finally {
- if (!noclip)
- NativeObject.setClip(oldClip);
- }
- }
- finally {
- NativeObject.setTransform(oldT);
- }
- }
- finally {
- NativeObject.setPaint(oldP);
- }
- }
- #endregion
- #region Container
- void PushGraphicsState(GraphicsState state) {
- state.Next = _nextGraphicsState;
- _nextGraphicsState = state;
- }
- GraphicsState PopGraphicsState() {
- GraphicsState state = _nextGraphicsState;
- _nextGraphicsState = _nextGraphicsState.Next;
- return state;
- }
- bool ContainsGraphicsState(GraphicsState state) {
- GraphicsState gs = _nextGraphicsState;
- while(gs != null) {
- if (gs == state)
- return true;
- gs = gs.Next;
- }
- return false;
- }
- public void EndContainer (GraphicsContainer container) {
- Restore(container.StateObject);
- }
- public GraphicsContainer BeginContainer () {
- return new GraphicsContainer(Save(Matrix.IdentityTransform, true));
- }
-
- public GraphicsContainer BeginContainer (Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit) {
- Matrix containerTransfrom =
- new Matrix( srcrect,
- new Point [] { new Point (dstrect.X, dstrect.Y),
- new Point (dstrect.X + dstrect.Width, dstrect.Y),
- new Point (dstrect.X, dstrect.Y + dstrect.Height) });
- float scale = _unitConversion[ (int)PageUnit ] / _unitConversion[ (int)unit ];
- containerTransfrom.Scale(scale, scale);
- return new GraphicsContainer(Save(containerTransfrom, true));
- }
-
- public GraphicsContainer BeginContainer (RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit) {
- Matrix containerTransfrom =
- new Matrix( srcrect,
- new PointF [] { new PointF (dstrect.X, dstrect.Y),
- new PointF (dstrect.X + dstrect.Width, dstrect.Y),
- new PointF (dstrect.X, dstrect.Y + dstrect.Height) });
- float scale = _unitConversion[ (int)PageUnit ] / _unitConversion[ (int)unit ];
- containerTransfrom.Scale(scale, scale);
- return new GraphicsContainer(Save(containerTransfrom, true));
- }
- GraphicsState Save(Matrix matrix, bool resetState) {
- GraphicsState graphicsState = new GraphicsState(this, matrix, resetState);
- PushGraphicsState( graphicsState );
- return graphicsState;
- }
- public GraphicsState Save () {
- return Save(Matrix.IdentityTransform, false);
- }
- public void Restore (GraphicsState graphicsState) {
- if (ContainsGraphicsState(graphicsState)) {
- GraphicsState gs = PopGraphicsState();
- while ( gs != graphicsState )
- gs = PopGraphicsState();
- graphicsState.RestoreState(this);
- }
- }
- #endregion
- #region Metafiles Staff
- [MonoTODO]
- public void AddMetafileComment (byte [] data) {
- throw new NotImplementedException ();
- }
- #if INTPTR_SUPPORT
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
- {
- throw new NotImplementedException ();
- }
- #endif
- #endregion
- #region ExcludeClip
- void ExcludeClip(geom.Area area) {
- geom.AffineTransform t = GetFinalTransform();
- if (!t.isIdentity()) {
- area = (geom.Area) area.MemberwiseClone ();
- area.transform(t);
- }
- _clip.NativeObject.subtract(area);
- RestoreBaseClip();
- NativeObject.clip(_clip);
- }
- public void ExcludeClip (Rectangle rect) {
- ExcludeClip(new geom.Area(rect.NativeObject));
- }
- public void ExcludeClip (Region region) {
- if (region == null)
- throw new ArgumentNullException("region");
- ExcludeClip(region.NativeObject);
- }
- #endregion
- #region FillClosedCurve
- public void FillClosedCurve (Brush brush, PointF [] points) {
- FillClosedCurve (brush, points, FillMode.Alternate);
- }
-
- public void FillClosedCurve (Brush brush, Point [] points) {
- FillClosedCurve (brush, points, FillMode.Alternate);
- }
-
- public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode) {
- FillClosedCurve (brush, points, fillmode, 0.5f);
- }
-
- public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode) {
- FillClosedCurve (brush, points, fillmode, 0.5f);
- }
- public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode, float tension) {
- GraphicsPath path = new GraphicsPath(fillmode);
- path.AddClosedCurve(points, tension);
- FillPath(brush, path);
- }
- public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode, float tension) {
- GraphicsPath path = new GraphicsPath(fillmode);
- path.AddClosedCurve(points, tension);
- FillPath(brush, path);
- }
- #endregion
- #region FillEllipse
- public void FillEllipse (Brush brush, Rectangle rect) {
- FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
- }
- public void FillEllipse (Brush brush, RectangleF rect) {
- FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
- }
- public void FillEllipse (Brush brush, float x, float y, float width, float height) {
- FillShape(brush,new java.awt.geom.Ellipse2D.Float(x,y,width,height));
- }
- public void FillEllipse (Brush brush, int x, int y, int width, int height) {
- FillEllipse (brush,(float)x,(float)y,(float)width,(float)height);
- }
- #endregion
- #region FillPath
- public void FillPath (Brush brush, GraphicsPath path) {
- if (path == null)
- throw new ArgumentNullException("path");
- FillShape(brush,path);
- }
- #endregion
- #region FillPie
- public void FillPie (Brush brush, Rectangle rect, float startAngle, float sweepAngle) {
- FillPie(brush,(float)rect.X,(float)rect.Y,(float)rect.Width,(float)rect.Height,(float)startAngle,(float)sweepAngle);
- }
- public void FillPie (Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle) {
- FillPie(brush,(float)x,(float)y,(float)width,(float)height,(float)startAngle,(float)sweepAngle);
- }
- public void FillPie (Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle) {
- GraphicsPath path = new GraphicsPath();
- path.AddPie(x, y, width, height, startAngle, sweepAngle);
- FillPath(brush, path);
- }
- #endregion
- #region FillPolygon
- public void FillPolygon (Brush brush, PointF [] points) {
- FillPolygon(brush, points, FillMode.Alternate);
- }
- public void FillPolygon (Brush brush, Point [] points) {
- FillPolygon(brush, points, FillMode.Alternate);
- }
- public void FillPolygon (Brush brush, Point [] points, FillMode fillMode) {
- GraphicsPath path = new GraphicsPath(fillMode);
- path.AddPolygon(points);
- FillPath(brush,path);
- }
- public void FillPolygon (Brush brush, PointF [] points, FillMode fillMode) {
- GraphicsPath path = new GraphicsPath(fillMode);
- path.AddPolygon(points);
- FillPath(brush,path);
- }
- #endregion
- #region FillRectangle
- public void FillRectangle (Brush brush, RectangleF rect) {
- FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
- }
- public void FillRectangle (Brush brush, Rectangle rect) {
- FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
- }
- public void FillRectangle (Brush brush, int x, int y, int width, int height) {
- FillRectangle(brush,(float)x,(float)y,(float)width,(float)height);
- }
- public void FillRectangle (Brush brush, float x, float y, float width, float height) {
- FillShape(brush,new java.awt.geom.Rectangle2D.Float(x,y,width,height));
- }
- public void FillRectangles (Brush brush, Rectangle [] rects) {
- GraphicsPath path = new GraphicsPath();
- path.AddRectangles(rects);
- FillPath(brush,path);
- }
- public void FillRectangles (Brush brush, RectangleF [] rects) {
- GraphicsPath path = new GraphicsPath();
- path.AddRectangles(rects);
- FillPath(brush,path);
- }
- #endregion
- #region FillRegion
- public void FillRegion (Brush brush, Region region) {
- FillShape(brush,region);
- }
- #endregion
- public void Flush () {
- Flush (FlushIntention.Flush);
- }
-
- public void Flush (FlushIntention intention) {
- if (_image != null)
- _image.NativeObject.CurrentImage.NativeImage.flush();
- }
- #if INTPTR_SUPPORTED
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [MonoTODO]
- public void ReleaseHdc (IntPtr hdc)
- {
- throw new NotImplementedException();
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [MonoTODO]
- public void ReleaseHdcInternal (IntPtr hdc)
- {
- throw new NotImplementedException ();
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [MonoTODO]
- public static Graphics FromHdc (IntPtr hdc)
- {
- throw new NotImplementedException();
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [MonoTODO]
- public static Graphics FromHdc (IntPtr hdc, IntPtr hdevice)
- {
- throw new NotImplementedException ();
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [MonoTODO]
- public static Graphics FromHdcInternal (IntPtr hdc)
- {
- throw new NotImplementedException ();
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [MonoTODO]
- public static Graphics FromHwnd (IntPtr hwnd)
- {
- throw new NotImplementedException();
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [MonoTODO]
- public static Graphics FromHwndInternal (IntPtr hwnd)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- internal static Graphics FromXDrawable (IntPtr drawable, IntPtr display)
- {
- throw new NotImplementedException();
- }
- [MonoTODO]
- public static IntPtr GetHalftonePalette ()
- {
- throw new NotImplementedException ();
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [MonoTODO]
- public IntPtr GetHdc ()
- {
- throw new NotImplementedException();
- }
- #endif
-
- #region GetNearestColor
- [MonoTODO]
- public Color GetNearestColor (Color color) {
- throw new NotImplementedException();
- }
- #endregion
- #region IntersectClip
- void IntersectClip (geom.Area area) {
-
- geom.AffineTransform t = GetFinalTransform();
- if (!t.isIdentity()) {
- area = (geom.Area) area.MemberwiseClone ();
- area.transform(t);
- }
- _clip.NativeObject.intersect(area);
- RestoreBaseClip();
- NativeObject.clip(_clip);
- }
- public void IntersectClip (Region region) {
- if (region == null)
- throw new ArgumentNullException("region");
- IntersectClip(region.NativeObject);
- }
-
- public void IntersectClip (RectangleF rect) {
- IntersectClip(new geom.Area(rect.NativeObject));
- }
- public void IntersectClip (Rectangle rect) {
- IntersectClip(new geom.Area(rect.NativeObject));
- }
- #endregion
- #region IsVisible
- public bool IsVisible (Point point) {
- return IsVisible(point.X,point.Y);
- }
-
- public bool IsVisible (RectangleF rect) {
- return IsVisible ((float)rect.X,(float)rect.Y,(float)rect.Width,(float)rect.Height);
- }
- public bool IsVisible (PointF point) {
- return IsVisible(point.X,point.Y);
- }
-
- public bool IsVisible (Rectangle rect) {
- return IsVisible ((float)rect.X,(float)rect.Y,(float)rect.Width,(float)rect.Height);
- }
-
- public bool IsVisible (float x, float y) {
- double dx = x;
- double dy = y;
- geom.AffineTransform t = GetFinalTransform();
- if (!t.isIdentity()) {
- double[] p = new double[] {dx, dy};
- t.transform(p, 0, p, 0, 1);
- dx = p[0];
- dy = p[1];
- }
- if (!_clip.NativeObject.contains(dx, dy))
- return false;
- awt.Shape clip = NativeObject.getClip();
- if (clip == null)
- return true;
- return clip.contains(dx, dy);
- }
-
- public bool IsVisible (int x, int y) {
- return IsVisible ((float)x,(float)y);
- }
-
- public bool IsVisible (float x, float y, float width, float height) {
- geom.AffineTransform t = GetFinalTransform();
- geom.Rectangle2D r = new geom.Rectangle2D.Float(x, y, width, height);
-
- if (!t.isIdentity())
- r = t.createTransformedShape(r).getBounds2D();
-
- return NativeObject.hitClip(
- (int)(r.getX()+0.5), (int)(r.getY()+0.5),
- (int)(r.getWidth()+0.5), (int)(r.getHeight()+0.5))
- && _clip.NativeObject.intersects(r);
- }
-
- public bool IsVisible (int x, int y, int width, int height) {
- return IsVisible ((float)x,(float)y,(float)width,(float)height);
- }
- #endregion
- #region MeasureCharacterRanges
- public Region [] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat) {
- if (stringFormat == null)
- throw new ArgumentException("stringFormat");
- CharacterRange[] ranges = stringFormat.CharRanges;
- if (ranges == null || ranges.Length == 0)
- return new Region[0];
- GraphicsPath[] pathes = new GraphicsPath[ranges.Length];
- for (int i = 0; i < pathes.Length; i++)
- pathes[i] = new GraphicsPath();
- TextLineIterator iter = new TextLineIterator(text, font, NativeObject.getFontRenderContext(),
- stringFormat, layoutRect.Width, layoutRect.Height);
-
- for (LineLayout layout = iter.NextLine(); layout != null; layout = iter.NextLine()) {
- for (int i = 0; i < ranges.Length; i++) {
- int start = ranges[i].First;
- int length = ranges[i].Length;
- start -= iter.CharsConsumed;
- int limit = start + length;
- int layoutStart = iter.CurrentPosition - layout.CharacterCount;
- if (start < iter.CurrentPosition && limit > layoutStart) {
- float layoutOffset;
- if (start > layoutStart)
- layoutOffset = iter.GetAdvanceBetween(layoutStart, start);
- else {
- layoutOffset = 0;
- start = layoutStart;
- }
- float width = (limit < iter.CurrentPosition) ?
- iter.GetAdvanceBetween(start, limit) :
- layout.Width - layoutOffset;
- float height = layout.Ascent + layout.Descent;
- float x = layout.NativeX;
- float y = layout.NativeY;
- if (stringFormat.IsVertical) {
- y += layoutOffset;
- x -= layout.Descent;
- }
- else {
- x += layoutOffset;
- y -= layout.Ascent;
- }
- if (layout.AccumulatedHeight + height > iter.WrapHeight) {
- float diff = iter.WrapHeight - layout.AccumulatedHeight;
- if (stringFormat.IsVertical && stringFormat.IsRightToLeft) {
- x += diff;
- height -= diff;
- }
- else
- height = diff;
- }
- if (stringFormat.IsVertical)
- pathes[i].AddRectangle(x + layoutRect.X, y + layoutRect.Y, height, width);
- else
- pathes[i].AddRectangle(x + layoutRect.X, y + layoutRect.Y, width, height);
- }
- }
- }
- geom.AffineTransform lineAlignT = iter.CalcLineAlignmentTransform();
- if (lineAlignT != null) {
- for (int i = 0; i < pathes.Length; i++)
- pathes[i].NativeObject.transform(lineAlignT);
- }
- Region[] regions = new Region[ranges.Length];
- for (int i = 0; i < regions.Length; i++)
- regions[i] = new Region(pathes[i]);
- return regions;
- }
- #endregion
-
- #region MeasureString
- public SizeF MeasureString (string text, Font font) {
- return MeasureString(text, font, null, float.PositiveInfinity, float.PositiveInfinity, null);
- }
-
- public SizeF MeasureString (string text, Font font, SizeF layoutArea) {
- return MeasureString(text, font, layoutArea, null);
- }
-
- public SizeF MeasureString (string text, Font font, int width) {
- return MeasureString(text, font, width, null);
- }
- public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat format) {
- return MeasureString(text, font, format, layoutArea.Width, layoutArea.Height, null);
- }
-
- public SizeF MeasureString (string text, Font font, int width, StringFormat format) {
- return MeasureString(text, font, format, width, float.PositiveInfinity, null);
- }
-
- public SizeF MeasureString (string text, Font font, PointF origin, StringFormat format) {
- return MeasureString(text, font, format, float.PositiveInfinity, float.PositiveInfinity, null);
- }
- SizeF MeasureString (string text, Font font, StringFormat format, float width, float height, int[] statistics) {
- if (statistics != null) {
- statistics[0] = 0;
- statistics[1] = 0;
- }
- TextLineIterator iter = new TextLineIterator(text, font, NativeObject.getFontRenderContext(), format, width, height);
- float mwidth = 0;
- int linesFilled = 0;
- for (LineLayout layout = iter.NextLine(); layout != null; layout = iter.NextLine()) {
- linesFilled ++;
- float w = layout.MeasureWidth;
- if (w > mwidth)
- mwidth = w;
- }
- if (linesFilled == 0)
- return SizeF.Empty;
- float mheight = iter.AccumulatedHeight;
- if (format != null) {
- if (format.IsVertical) {
- float temp = mheight;
- mheight = mwidth;
- mwidth = temp;
- }
- }
- if (!(format != null && format.NoClip)) {
- if (mwidth > width)
- mwidth = width;
- if (mheight > height)
- mheight = height;
- }
- if (statistics != null) {
- statistics[0] = linesFilled;
- statistics[1] = iter.CharsConsumed;
- }
- return new SizeF(mwidth, mheight);
- }
-
- public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat, out int charactersFitted, out int linesFilled) {
- linesFilled = 0;
- charactersFitted = 0;
- int[] statistics = new int[2];
- SizeF sz = MeasureString(text, font, stringFormat, layoutArea.Width, layoutArea.Height, statistics);
- linesFilled = statistics[0];
- charactersFitted = statistics[1];
- return sz;
- }
- #endregion
- #region MultiplyTransform
- public void MultiplyTransform (Matrix matrix) {
- MultiplyTransform (matrix, MatrixOrder.Prepend);
- }
- public void MultiplyTransform (Matrix matrix, MatrixOrder order) {
- ConcatenateTransform(matrix.NativeObject, order);
- }
- #endregion
- #region Reset (Clip and Transform)
- public void ResetClip () {
- _clip.MakeInfinite();
- RestoreBaseClip();
- NativeObject.clip(_clip);
- }
- public void ResetTransform () {
- _transform.Reset();
- }
- #endregion
- #region RotateTransform
- public void RotateTransform (float angle) {
- RotateTransform (angle, MatrixOrder.Prepend);
- }
- public void RotateTransform (float angle, MatrixOrder order) {
- ConcatenateTransform(
- geom.AffineTransform.getRotateInstance(java.lang.Math.toRadians(angle)),
- order);
- }
- #endregion
- #region ScaleTransform
- public void ScaleTransform (float sx, float sy) {
- ScaleTransform (sx, sy, MatrixOrder.Prepend);
- }
- public void ScaleTransform (float sx, float sy, MatrixOrder order) {
- ConcatenateTransform(
- geom.AffineTransform.getScaleInstance(sx, sy),
- order);
- }
- #endregion
- #region SetClip [Must be reviewed - more abstraction needed]
- public void SetClip (RectangleF rect) {
- SetClip (rect, CombineMode.Replace);
- }
- public void SetClip (GraphicsPath path) {
- SetClip (path, CombineMode.Replace);
- }
- public void SetClip (Rectangle rect) {
- SetClip (rect, CombineMode.Replace);
- }
- public void SetClip (Graphics g) {
- SetClip (g, CombineMode.Replace);
- }
- public void SetClip (Graphics g, CombineMode combineMode) {
- if(g == null)
- throw new NullReferenceException();
-
- CombineClipArea(g._clip.NativeObject, combineMode);
- }
- public void SetClip (Rectangle rect, CombineMode combineMode) {
- SetClip(rect.X,rect.Y,rect.Width,rect.Height,combineMode);
- }
- public void SetClip (RectangleF rect, CombineMode combineMode) {
- SetClip(rect.X,rect.Y,rect.Width,rect.Height,combineMode);
- }
-
- public void SetClip (Region region, CombineMode combineMode) {
- if(region == null)
- throw new ArgumentNullException("region");
- CombineClipArea ((geom.Area) region.NativeObject.MemberwiseClone (), combineMode);
- }
-
- public void SetClip (GraphicsPath path, CombineMode combineMode) {
- if(path == null)
- throw new ArgumentNullException("path");
- CombineClipArea(new geom.Area(path.NativeObject), combineMode);
- }
- #endregion
- #region Clipping Staff [INTERNAL]
- internal Region ScaledClip {
- get {
- return _clip.Clone();
- }
- set {
- _clip.NativeObject.reset();
- _clip.NativeObject.add(value.NativeObject);
- }
- }
- internal void SetClip(float x,float y,float width,float height,CombineMode combineMode) {
- CombineClipArea(new geom.Area(
- new geom.Rectangle2D.Float(x,y,width,height)),combineMode);
- }
- void CombineClipArea(geom.Area area, CombineMode combineMode) {
- geom.AffineTransform t = GetFinalTransform();
- if (!t.isIdentity())
- area.transform(t);
- if (combineMode == CombineMode.Replace) {
- _clip.NativeObject.reset();
- _clip.NativeObject.add(area);
- }
- else {
- geom.Area curClip = _clip.NativeObject;
- switch(combineMode) {
- case CombineMode.Complement:
- curClip.add(area);
- break;
- case CombineMode.Exclude:
- curClip.subtract(area);
- break;
- case CombineMode.Intersect:
- curClip.intersect(area);
- break;
- case CombineMode.Union:
- curClip.add(area);
- break;
- case CombineMode.Xor:
- curClip.exclusiveOr(area);
- break;
- default:
- throw new ArgumentOutOfRangeException();
- }
- }
- RestoreBaseClip();
- NativeObject.clip(_clip);
- }
- internal void IntersectScaledClipWithBase(awt.Shape clip) {
- NativeObject.clip(clip);
- }
- void RestoreBaseClip() {
- if (_nextGraphicsState == null) {
- NativeObject.setClip(_windowRect);
- return;
- }
- _nextGraphicsState.RestoreBaseClip(this);
- }
-
- #endregion
-
- #region TransformPoints
- [MonoTODO]
- public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, PointF [] pts) {
- //TBD:CoordinateSpace
- java.awt.geom.AffineTransform tr = this.Transform.NativeObject;
- float[] fpts = new float[2];
- for(int i = 0; i< pts.Length; i++) {
- fpts[0] = pts[i].X;
- fpts[1] = pts[i].Y;
- tr.transform(fpts, 0, fpts, 0, 1);
- pts[i].X = fpts[0];
- pts[i].Y = fpts[1];
- }
- }
- [MonoTODO]
- public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, Point [] pts) {
- //TBD:CoordinateSpace
- java.awt.geom.AffineTransform tr = this.Transform.NativeObject;
- float[] fpts = new float[2];
- for(int i = 0; i< pts.Length; i++) {
- fpts[0] = pts[i].X;
- fpts[1] = pts[i].Y;
- tr.transform(fpts, 0, fpts, 0, 1);
- pts[i].X = (int)fpts[0];
- pts[i].Y = (int)fpts[1];
- }
- }
- #endregion
- #region TranslateClip
- public void TranslateClip (int dx, int dy) {
- TranslateClip((float)dx, (float)dy);
- }
-
- public void TranslateClip (float dx, float dy) {
- double x = dx;
- double y = dy;
- geom.AffineTransform f = GetFinalTransform();
- if (!f.isIdentity()) {
- double[] p = new double[] {x, y};
- f.deltaTransform(p, 0, p, 0, 1);
- x = p[0];
- y = p[1];
- }
- // It seems .Net does exactly this...
- x = Math.Floor(x+0.96875);
- y = Math.Floor(y+0.96875);
- geom.AffineTransform t = geom.AffineTransform.getTranslateInstance(x, y);
- _clip.NativeObject.transform(t);
- RestoreBaseClip();
- NativeObject.clip(_clip);
- }
- #endregion
- #region TranslateTransform
- public void TranslateTransform (float dx, float dy) {
- TranslateTransform (dx, dy, MatrixOrder.Prepend);
- }
-
- public void TranslateTransform (float dx, float dy, MatrixOrder order) {
- ConcatenateTransform(
- geom.AffineTransform.getTranslateInstance(dx, dy),
- order);
- }
- #endregion
- #region Properties [Partial TODO]
- public Region Clip {
- get {
- Region r = _clip.Clone();
- geom.AffineTransform t = GetFinalTransform();
- if (!t.isIdentity())
- r.NativeObject.transform(t.createInverse());
- return r;
- }
- set {
- SetClip (value, CombineMode.Replace);
- }
- }
- public RectangleF ClipBounds {
- get {
- awt.Shape shape = _clip.NativeObject;
- if (shape == null)
- shape = Region.InfiniteRegion.NativeObject;
- geom.RectangularShape r = shape.getBounds2D();
- geom.AffineTransform t = GetFinalTransform();
- if (!t.isIdentity()) {
- geom.AffineTransform it = t.createInverse();
- r = it.createTransformedShape(r).getBounds2D();
- }
- return new RectangleF (r);
- }
- }
- public CompositingMode CompositingMode {
- //TBD:check this carefully
- get {
- return (NativeObject.getComposite() == awt.AlphaComposite.SrcOver) ?
- CompositingMode.SourceOver : CompositingMode.SourceCopy;
- }
- set {
- NativeObject.setComposite(
- (value == CompositingMode.SourceOver) ?
- awt.AlphaComposite.SrcOver : awt.AlphaComposite.Src);
- }
- }
- public CompositingQuality CompositingQuality {
- get {
- awt.RenderingHints hints = NativeObject.getRenderingHints();
- if(hints.containsKey(awt.RenderingHints.KEY_ALPHA_INTERPOLATION)) {
- object value_ai = hints.get(awt.RenderingHints.KEY_ALPHA_INTERPOLATION);
- if (value_ai == awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)
- return CompositingQuality.HighSpeed;
- if (value_ai == awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)
- return CompositingQuality.HighQuality;
- if (value_ai == awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)
- return CompositingQuality.Default;
- }
- return CompositingQuality.Default;
-
- }
- set {
- awt.RenderingHints hints = NativeObject.getRenderingHints();
- switch (value) {
- case CompositingQuality.AssumeLinear:
- case CompositingQuality.Default:
- case CompositingQuality.GammaCorrected:
- hints.put(awt.RenderingHints.KEY_ALPHA_INTERPOLATION,
- awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT);
- break;
- case CompositingQuality.HighQuality:
- hints.put(awt.RenderingHints.KEY_ALPHA_INTERPOLATION,
- awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- break;
- case CompositingQuality.HighSpeed:
- hints.put(awt.RenderingHints.KEY_ALPHA_INTERPOLATION,
- awt.RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
- break;
- // case CompositingQuality.Invalid:
- // if(hints.containsKey(awt.RenderingHints.KEY_ALPHA_INTERPOLATION))
- // hints.remove(awt.RenderingHints.KEY_ALPHA_INTERPOLATION);
- }
- NativeObject.setRenderingHints(hints);
- }
- }
- public float DpiX {
- get {
- return DefaultScreenResolution;
- }
- }
- public float DpiY {
- get {
- //TBD: assume 72 (screen) for now
- return DpiX;
- }
- }
- public InterpolationMode InterpolationMode {
- get {
- awt.RenderingHints hints = NativeObject.getRenderingHints();
- if(hints.containsKey(awt.RenderingHints.KEY_INTERPOLATION)) {
- object value_i = hints.get(awt.RenderingHints.KEY_INTERPOLATION);
- if (value_i == awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR)
- return InterpolationMode.Bilinear;
- if (value_i == awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC)
- return InterpolationMode.Bicubic;
- if (value_i == awt.RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)
- return InterpolationMode.NearestNeighbor;
- }
- return InterpolationMode.Default;
- }
- set {
- awt.RenderingHints hints = NativeObject.getRenderingHints();
- switch (value) {
- case InterpolationMode.Bicubic:
- case InterpolationMode.HighQualityBicubic:
- case InterpolationMode.Low:
- hints.put(awt.RenderingHints.KEY_INTERPOLATION, awt.RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- break;
- case InterpolationMode.High:
- case InterpolationMode.Bilinear:
- case InterpolationMode.HighQualityBilinear:
- hints.put(awt.RenderingHints.KEY_INTERPOLATION, awt.RenderingHints.VALUE_INTERPOLATION_BILINEAR);
- break;
- case InterpolationMode.Default:
- if (hints.containsKey(awt.RenderingHints.KEY_INTERPOLATION))
- hints.remove(awt.RenderingHints.KEY_INTERPOLATION);
- break;
- case InterpolationMode.NearestNeighbor:
- hints.put(awt.RenderingHints.KEY_INTERPOLATION, awt.RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
- break;
- case InterpolationMode.Invalid:
- throw new ArgumentException();
- default:
- throw new ArgumentOutOfRangeException();
- }
- NativeObject.setRenderingHints(hints);
- }
- }
- public bool IsClipEmpty {
- get {
- return _clip.IsEmpty(this);
- }
- }
- public bool IsVisibleClipEmpty {
- get {
- if (_clip.IsEmpty(this))
- return true;
- return VisibleClipBounds.IsEmpty;
- }
- }
- public float PageScale {
- get {
- return _pageScale;
- }
- set {
- _pageScale = value;
- }
- }
- public GraphicsUnit PageUnit {
- get {
- return _pageUnit;
- }
- set {
- _pageUnit = value;
- }
- }
- static internal geom.AffineTransform GetFinalTransform(
- geom.AffineTransform transform, GraphicsUnit pageUnit, float pageScale) {
- geom.AffineTransform t = null;
- if (pageUnit != GraphicsUnit.Display) {
- float scale = pageScale * _unitConversion[ (int)pageUnit ];
- if (Math.Abs(scale-1f) > float.Epsilon)
- t = geom.AffineTransform.getScaleInstance(scale, scale);
- }
- if (t != null)
- t.concatenate(transform);
- else
- t = transform;
-
- return t;
- }
- geom.AffineTransform GetFinalTransform() {
- return GetFinalTransform(_transform.NativeObject, PageUnit, PageScale);
- }
- public PixelOffsetMode PixelOffsetMode {
- get {
- return _pixelOffsetMode;
- }
- set {
- _pixelOffsetMode = value;
- }
- }
- [MonoTODO]
- public Point RenderingOrigin {
- get {
- throw new NotImplementedException();
- }
- set {
- throw new NotImplementedException();
- }
- }
- public SmoothingMode SmoothingMode {
- get {
- awt.RenderingHints hints = NativeObject.getRenderingHints();
- if(hints.containsKey(awt.RenderingHints.KEY_ANTIALIASING)) {
- object value_aa = hints.get(awt.RenderingHints.KEY_ANTIALIASING);
- if (value_aa == awt.RenderingHints.VALUE_ANTIALIAS_ON) {
- if(hints.containsKey(awt.RenderingHints.KEY_RENDERING)) {
- object value_render = hints.get(awt.RenderingHints.KEY_RENDERING);
- if (value_render == awt.RenderingHints.VALUE_RENDER_QUALITY)
- return SmoothingMode.HighQuality;
- if (value_render == awt.RenderingHints.VALUE_RENDER_SPEED)
- return SmoothingMode.HighSpeed;
- }
- return SmoothingMode.AntiAlias;
- }
- if (value_aa == awt.RenderingHints.VALUE_ANTIALIAS_DEFAULT)
- return SmoothingMode.Default;
- }
- return SmoothingMode.None;
- }
- set {
- awt.RenderingHints hints = NativeObject.getRenderingHints();
- switch (value) {
- case SmoothingMode.None:
- if(hints.containsKey(awt.RenderingHints.KEY_ANTIALIASING))
- hints.remove(awt.RenderingHints.KEY_ANTIALIASING);
- if(hints.containsKey(awt.RenderingHints.KEY_RENDERING))
- hints.remove(awt.RenderingHints.KEY_RENDERING);
- break;
- case SmoothingMode.AntiAlias:
- hints.put(awt.RenderingHints.KEY_ANTIALIASING, awt.RenderingHints.VALUE_ANTIALIAS_ON);
- break;
- case SmoothingMode.HighQuality:
- hints.put(awt.RenderingHints.KEY_RENDERING, awt.RenderingHints.VALUE_RENDER_QUALITY);
- goto case SmoothingMode.AntiAlias;
- case SmoothingMode.HighSpeed:
- hints.put(awt.RenderingHints.KEY_RENDERING, awt.RenderingHints.VALUE_RENDER_SPEED);
- goto case SmoothingMode.None;
- case SmoothingMode.Default:
- hints.put(awt.RenderingHints.KEY_RENDERING, awt.RenderingHints.VALUE_RENDER_DEFAULT);
- goto case SmoothingMode.AntiAlias;
- case SmoothingMode.Invalid:
- throw new ArgumentException("Invalid parameter used.");
- }
- NativeObject.setRenderingHints(hints);
- }
- }
- /// <summary>
- /// Java does not have similar functionality
- /// </summary>
- public int TextContrast {
- get {
- return _textContrast;
- }
- set {
- _textContrast = value;
- }
- }
- public TextRenderingHint TextRenderingHint {
- get {
- return _textRenderingHint;
- // awt.RenderingHints hints = NativeObject.getRenderingHints();
- // if(hints.containsKey(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING)) {
- // if(hints.get(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING) ==
- // java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON)
- // return TextRenderingHint.AntiAlias;
- // if(hints.get(java.awt.RenderingHints.KEY_TEXT_ANTIALIASING) ==
- // java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
- // return TextRenderingHint.SingleBitPerPixel;
- // }
- // //return TextRenderingHint.SystemDefault;
- // return TextRenderingHint.SingleBitPerPixelGridFit;
- }
- set {
- _textRenderingHint = value;
- awt.RenderingHints hints = NativeObject.getRenderingHints();
- switch (value) {
- case TextRenderingHint.AntiAlias:
- case TextRenderingHint.AntiAliasGridFit:
- case TextRenderingHint.ClearTypeGridFit:
- // case TextRenderingHint.SystemDefault:
- hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
- awt.RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- break;
-
- case TextRenderingHint.SingleBitPerPixelGridFit:
- hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
- awt.RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
- break;
- case TextRenderingHint.SingleBitPerPixel:
- hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
- awt.RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
- break;
- case TextRenderingHint.SystemDefault:
- hints.put(awt.RenderingHints.KEY_TEXT_ANTIALIASING,
- awt.RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
- break;
- }
-
- NativeObject.setRenderingHints(hints);
- }
- }
- public Matrix Transform {
- get {
- return _transform.Clone();
- }
- set {
- if (value == null)
- throw new ArgumentNullException("matrix");
- if (!value.IsInvertible)
- throw new ArgumentException("Invalid parameter used.");
- value.CopyTo(_transform);
- }
- }
- internal Matrix BaseTransform {
- get {
- return new Matrix(NativeObject.getTransform());
- }
- set {
- NativeObject.setTransform(value.NativeObject);
- }
- }
- internal void PrependBaseTransform(geom.AffineTransform t) {
- NativeObject.transform(t);
- }
- internal awt.Shape VisibleShape {
- get {
- return _windowRect;
- }
- }
- public RectangleF VisibleClipBounds {
- get {
- if (_clip.IsEmpty(this))
- return RectangleF.Empty;
- geom.Rectangle2D r = _clip.NativeObject.getBounds2D();
- awt.Shape clip = NativeObject.getClip();
- geom.Rectangle2D clipBounds = (clip != null) ? clip.getBounds2D() : _windowRect;
- geom.Rectangle2D.intersect(r, clipBounds, r);
- if ((r.getWidth() <= 0) || (r.getHeight() <= 0))
- return RectangleF.Empty;
- geom.AffineTransform t = GetFinalTransform();
- if (!t.isIdentity()) {
- geom.AffineTransform it = t.createInverse();
- r = it.createTransformedShape(r).getBounds2D();
- }
- return new RectangleF (r);
- }
- }
- void ConcatenateTransform(geom.AffineTransform transform, MatrixOrder order) {
- geom.AffineTransform at = _transform.NativeObject;
- Matrix.Multiply(at, transform, order);
- }
- #endregion
- }
- }
|