| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655 |
- //
- // Graphics class testing unit
- //
- // Authors:
- // Jordi Mas, [email protected]
- // Sebastien Pouliot <[email protected]>
- //
- // Copyright (C) 2005-2008 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using NUnit.Framework;
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.Drawing.Text;
- using System.IO;
- using System.Reflection;
- using System.Security.Permissions;
- namespace MonoTests.System.Drawing {
- [TestFixture]
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
- public class GraphicsTest {
- private RectangleF[] rects;
- private Font font;
- [TestFixtureSetUp]
- public void FixtureSetUp ()
- {
- try {
- font = new Font ("Arial", 12);
- }
- catch {
- }
- }
- [TestFixtureTearDown]
- public void FixtureTearDown ()
- {
- if (font != null)
- font.Dispose ();
- }
- private bool IsEmptyBitmap (Bitmap bitmap, out int x, out int y)
- {
- bool result = true;
- int empty = Color.Empty.ToArgb ();
- #if false
- for (y = 0; y < bitmap.Height; y++) {
- for (x = 0; x < bitmap.Width; x++) {
- if (bitmap.GetPixel (x, y).ToArgb () != empty) {
- Console.Write ("X");
- result = false;
- } else
- Console.Write (" ");
- }
- Console.WriteLine ();
- }
- #else
- for (y = 0; y < bitmap.Height; y++) {
- for (x = 0; x < bitmap.Width; x++) {
- if (bitmap.GetPixel (x, y).ToArgb () != empty)
- return false;
- }
- }
- #endif
- x = -1;
- y = -1;
- return result;
- }
- private void CheckForEmptyBitmap (Bitmap bitmap)
- {
- int x, y;
- if (!IsEmptyBitmap (bitmap, out x, out y))
- Assert.Fail (String.Format ("Position {0},{1}", x, y));
- }
- private void CheckForNonEmptyBitmap (Bitmap bitmap)
- {
- int x, y;
- if (IsEmptyBitmap (bitmap, out x, out y))
- Assert.Fail ("Bitmap was empty");
- }
- private void AssertEquals (string msg, object expected, object actual)
- {
- Assert.AreEqual (expected, actual, msg);
- }
- private void AssertEquals (string msg, double expected, double actual, double delta)
- {
- Assert.AreEqual (expected, actual, delta, msg);
- }
- [Test]
- public void DefaultProperties ()
- {
- Bitmap bmp = new Bitmap (200, 200);
- Graphics g = Graphics.FromImage (bmp);
- Region r = new Region ();
- Assert.AreEqual (r.GetBounds (g), g.ClipBounds, "DefaultProperties1");
- Assert.AreEqual (CompositingMode.SourceOver, g.CompositingMode, "DefaultProperties2");
- Assert.AreEqual (CompositingQuality.Default, g.CompositingQuality, "DefaultProperties3");
- Assert.AreEqual (InterpolationMode.Bilinear, g.InterpolationMode, "DefaultProperties4");
- Assert.AreEqual (1, g.PageScale, "DefaultProperties5");
- Assert.AreEqual (GraphicsUnit.Display, g.PageUnit, "DefaultProperties6");
- Assert.AreEqual (PixelOffsetMode.Default, g.PixelOffsetMode, "DefaultProperties7");
- Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "DefaultProperties8");
- Assert.AreEqual (SmoothingMode.None, g.SmoothingMode, "DefaultProperties9");
- Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "DefaultProperties10");
- r.Dispose ();
- }
- [Test]
- public void SetGetProperties ()
- {
- Bitmap bmp = new Bitmap (200, 200);
- Graphics g = Graphics.FromImage (bmp);
- g.CompositingMode = CompositingMode.SourceCopy;
- g.CompositingQuality = CompositingQuality.GammaCorrected;
- g.InterpolationMode = InterpolationMode.HighQualityBilinear;
- g.PageScale = 2;
- g.PageUnit = GraphicsUnit.Inch;
- g.PixelOffsetMode = PixelOffsetMode.Half;
- g.RenderingOrigin = new Point (10, 20);
- g.SmoothingMode = SmoothingMode.AntiAlias;
- g.TextRenderingHint = TextRenderingHint.SystemDefault;
- //Clipping set/get tested in clipping functions
- Assert.AreEqual (CompositingMode.SourceCopy, g.CompositingMode, "SetGetProperties2");
- Assert.AreEqual (CompositingQuality.GammaCorrected, g.CompositingQuality, "SetGetProperties3");
- Assert.AreEqual (InterpolationMode.HighQualityBilinear, g.InterpolationMode, "SetGetProperties4");
- Assert.AreEqual (2, g.PageScale, "SetGetProperties5");
- Assert.AreEqual (GraphicsUnit.Inch, g.PageUnit, "SetGetProperties6");
- Assert.AreEqual (PixelOffsetMode.Half, g.PixelOffsetMode, "SetGetProperties7");
- Assert.AreEqual (new Point (10, 20), g.RenderingOrigin, "SetGetProperties8");
- Assert.AreEqual (SmoothingMode.AntiAlias, g.SmoothingMode, "SetGetProperties9");
- Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "SetGetProperties10");
- }
- // Properties
- [Test]
- public void Clip ()
- {
- RectangleF[] rects;
- Bitmap bmp = new Bitmap (200, 200);
- Graphics g = Graphics.FromImage (bmp);
- g.Clip = new Region (new Rectangle (50, 40, 210, 220));
- rects = g.Clip.GetRegionScans (new Matrix ());
- Assert.AreEqual (1, rects.Length, "Clip1");
- Assert.AreEqual (50, rects[0].X, "Clip2");
- Assert.AreEqual (40, rects[0].Y, "Clip3");
- Assert.AreEqual (210, rects[0].Width, "Clip4");
- Assert.AreEqual (220, rects[0].Height, "Clip5");
- }
- [Test]
- public void Clip_NotAReference ()
- {
- Bitmap bmp = new Bitmap (200, 200);
- Graphics g = Graphics.FromImage (bmp);
- Assert.IsTrue (g.Clip.IsInfinite (g), "IsInfinite");
- g.Clip.IsEmpty (g);
- Assert.IsFalse (g.Clip.IsEmpty (g), "!IsEmpty");
- Assert.IsTrue (g.Clip.IsInfinite (g), "IsInfinite-2");
- }
- [Test]
- public void ExcludeClip ()
- {
- Bitmap bmp = new Bitmap (200, 200);
- Graphics g = Graphics.FromImage (bmp);
- g.Clip = new Region (new RectangleF (10, 10, 100, 100));
- g.ExcludeClip (new Rectangle (40, 60, 100, 20));
- rects = g.Clip.GetRegionScans (new Matrix ());
- Assert.AreEqual (3, rects.Length, "ExcludeClip1");
- Assert.AreEqual (10, rects[0].X, "ExcludeClip2");
- Assert.AreEqual (10, rects[0].Y, "ExcludeClip3");
- Assert.AreEqual (100, rects[0].Width, "ExcludeClip4");
- Assert.AreEqual (50, rects[0].Height, "ExcludeClip5");
- Assert.AreEqual (10, rects[1].X, "ExcludeClip6");
- Assert.AreEqual (60, rects[1].Y, "ExcludeClip7");
- Assert.AreEqual (30, rects[1].Width, "ExcludeClip8");
- Assert.AreEqual (20, rects[1].Height, "ExcludeClip9");
- Assert.AreEqual (10, rects[2].X, "ExcludeClip10");
- Assert.AreEqual (80, rects[2].Y, "ExcludeClip11");
- Assert.AreEqual (100, rects[2].Width, "ExcludeClip12");
- Assert.AreEqual (30, rects[2].Height, "ExcludeClip13");
- }
- [Test]
- public void IntersectClip ()
- {
- Bitmap bmp = new Bitmap (200, 200);
- Graphics g = Graphics.FromImage (bmp);
- g.Clip = new Region (new RectangleF (260, 30, 60, 80));
- g.IntersectClip (new Rectangle (290, 40, 60, 80));
- rects = g.Clip.GetRegionScans (new Matrix ());
- Assert.AreEqual (1, rects.Length, "IntersectClip");
- Assert.AreEqual (290, rects[0].X, "IntersectClip");
- Assert.AreEqual (40, rects[0].Y, "IntersectClip");
- Assert.AreEqual (30, rects[0].Width, "IntersectClip");
- Assert.AreEqual (70, rects[0].Height, "IntersectClip");
- }
- [Test]
- public void ResetClip ()
- {
- Bitmap bmp = new Bitmap (200, 200);
- Graphics g = Graphics.FromImage (bmp);
- g.Clip = new Region (new RectangleF (260, 30, 60, 80));
- g.IntersectClip (new Rectangle (290, 40, 60, 80));
- g.ResetClip ();
- rects = g.Clip.GetRegionScans (new Matrix ());
- Assert.AreEqual (1, rects.Length, "ResetClip");
- Assert.AreEqual (-4194304, rects[0].X, "ResetClip");
- Assert.AreEqual (-4194304, rects[0].Y, "ResetClip");
- Assert.AreEqual (8388608, rects[0].Width, "ResetClip");
- Assert.AreEqual (8388608, rects[0].Height, "ResetClip");
- }
- [Test]
- public void SetClip ()
- {
- RectangleF[] rects;
- Bitmap bmp = new Bitmap (200, 200);
- Graphics g = Graphics.FromImage (bmp);
- // Region
- g.SetClip (new Region (new Rectangle (50, 40, 210, 220)), CombineMode.Replace);
- rects = g.Clip.GetRegionScans (new Matrix ());
- Assert.AreEqual (1, rects.Length, "SetClip1");
- Assert.AreEqual (50, rects[0].X, "SetClip2");
- Assert.AreEqual (40, rects[0].Y, "SetClip3");
- Assert.AreEqual (210, rects[0].Width, "SetClip4");
- Assert.AreEqual (220, rects[0].Height, "SetClip5");
- // RectangleF
- g = Graphics.FromImage (bmp);
- g.SetClip (new RectangleF (50, 40, 210, 220));
- rects = g.Clip.GetRegionScans (new Matrix ());
- Assert.AreEqual (1, rects.Length, "SetClip6");
- Assert.AreEqual (50, rects[0].X, "SetClip7");
- Assert.AreEqual (40, rects[0].Y, "SetClip8");
- Assert.AreEqual (210, rects[0].Width, "SetClip9");
- Assert.AreEqual (220, rects[0].Height, "SetClip10");
- // Rectangle
- g = Graphics.FromImage (bmp);
- g.SetClip (new Rectangle (50, 40, 210, 220));
- rects = g.Clip.GetRegionScans (new Matrix ());
- Assert.AreEqual (1, rects.Length, "SetClip10");
- Assert.AreEqual (50, rects[0].X, "SetClip11");
- Assert.AreEqual (40, rects[0].Y, "SetClip12");
- Assert.AreEqual (210, rects[0].Width, "SetClip13");
- Assert.AreEqual (220, rects[0].Height, "SetClip14");
- }
- [Test]
- public void SetSaveReset ()
- {
- Bitmap bmp = new Bitmap (200, 200);
- Graphics g = Graphics.FromImage (bmp);
- GraphicsState state_default, state_modified;
- state_default = g.Save (); // Default
- g.CompositingMode = CompositingMode.SourceCopy;
- g.CompositingQuality = CompositingQuality.GammaCorrected;
- g.InterpolationMode = InterpolationMode.HighQualityBilinear;
- g.PageScale = 2;
- g.PageUnit = GraphicsUnit.Inch;
- g.PixelOffsetMode = PixelOffsetMode.Half;
- g.Clip = new Region (new Rectangle (0, 0, 100, 100));
- g.RenderingOrigin = new Point (10, 20);
- g.SmoothingMode = SmoothingMode.AntiAlias;
- g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- state_modified = g.Save (); // Modified
- g.CompositingMode = CompositingMode.SourceOver;
- g.CompositingQuality = CompositingQuality.Default;
- g.InterpolationMode = InterpolationMode.Bilinear;
- g.PageScale = 5;
- g.PageUnit = GraphicsUnit.Display;
- g.PixelOffsetMode = PixelOffsetMode.Default;
- g.Clip = new Region (new Rectangle (1, 2, 20, 25));
- g.RenderingOrigin = new Point (5, 6);
- g.SmoothingMode = SmoothingMode.None;
- g.TextRenderingHint = TextRenderingHint.SystemDefault;
- g.Restore (state_modified);
- Assert.AreEqual (CompositingMode.SourceCopy, g.CompositingMode, "SetSaveReset1");
- Assert.AreEqual (CompositingQuality.GammaCorrected, g.CompositingQuality, "SetSaveReset2");
- Assert.AreEqual (InterpolationMode.HighQualityBilinear, g.InterpolationMode, "SetSaveReset3");
- Assert.AreEqual (2, g.PageScale, "SetSaveReset4");
- Assert.AreEqual (GraphicsUnit.Inch, g.PageUnit, "SetSaveReset5");
- Assert.AreEqual (PixelOffsetMode.Half, g.PixelOffsetMode, "SetSaveReset6");
- Assert.AreEqual (new Point (10, 20), g.RenderingOrigin, "SetSaveReset7");
- Assert.AreEqual (SmoothingMode.AntiAlias, g.SmoothingMode, "SetSaveReset8");
- Assert.AreEqual (TextRenderingHint.ClearTypeGridFit, g.TextRenderingHint, "SetSaveReset9");
- Assert.AreEqual (0, (int) g.ClipBounds.X, "SetSaveReset10");
- Assert.AreEqual (0, (int) g.ClipBounds.Y, "SetSaveReset10");
- g.Restore (state_default);
- Assert.AreEqual (CompositingMode.SourceOver, g.CompositingMode, "SetSaveReset11");
- Assert.AreEqual (CompositingQuality.Default, g.CompositingQuality, "SetSaveReset12");
- Assert.AreEqual (InterpolationMode.Bilinear, g.InterpolationMode, "SetSaveReset13");
- Assert.AreEqual (1, g.PageScale, "SetSaveReset14");
- Assert.AreEqual (GraphicsUnit.Display, g.PageUnit, "SetSaveReset15");
- Assert.AreEqual (PixelOffsetMode.Default, g.PixelOffsetMode, "SetSaveReset16");
- Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "SetSaveReset17");
- Assert.AreEqual (SmoothingMode.None, g.SmoothingMode, "SetSaveReset18");
- Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "SetSaveReset19");
- Region r = new Region ();
- Assert.AreEqual (r.GetBounds (g), g.ClipBounds, "SetSaveReset20");
- g.Dispose ();
- }
- [Test]
- [Category ("NotWorking")] // looks like MS PNG codec promote indexed format to 32bpp ARGB
- public void LoadIndexed_PngStream ()
- {
- // Tests that we can load an indexed file
- using (Stream s = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("indexed.png")) {
- using (Image img = Image.FromStream (s)) {
- // however it's no more indexed once loaded
- Assert.AreEqual (PixelFormat.Format32bppArgb, img.PixelFormat, "PixelFormat");
- using (Graphics g = Graphics.FromImage (img)) {
- Assert.AreEqual (img.Height, g.VisibleClipBounds.Height, "Height");
- Assert.AreEqual (img.Width, g.VisibleClipBounds.Width, "Width");
- }
- }
- }
- }
- [Test]
- [ExpectedException (typeof (Exception))]
- public void LoadIndexed_BmpFile ()
- {
- // Tests that we can load an indexed file, but...
- string sInFile = TestBitmap.getInFile ("bitmaps/almogaver1bit.bmp");
- // note: file is misnamed (it's a 4bpp bitmap)
- using (Image img = Image.FromFile (sInFile)) {
- Assert.AreEqual (PixelFormat.Format4bppIndexed, img.PixelFormat, "PixelFormat");
- Graphics.FromImage (img);
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void FromImage ()
- {
- Graphics g = Graphics.FromImage (null);
- }
- private Graphics Get (int w, int h)
- {
- Bitmap bitmap = new Bitmap (w, h);
- Graphics g = Graphics.FromImage (bitmap);
- g.Clip = new Region (new Rectangle (0, 0, w, h));
- return g;
- }
- private void Compare (string msg, RectangleF b1, RectangleF b2)
- {
- AssertEquals (msg + ".compare.X", b1.X, b2.X);
- AssertEquals (msg + ".compare.Y", b1.Y, b2.Y);
- AssertEquals (msg + ".compare.Width", b1.Width, b2.Width);
- AssertEquals (msg + ".compare.Height", b1.Height, b2.Height);
- }
- [Test]
- public void Clip_GetBounds ()
- {
- Graphics g = Get (16, 16);
- RectangleF bounds = g.Clip.GetBounds (g);
- Assert.AreEqual (0, bounds.X, "X");
- Assert.AreEqual (0, bounds.Y, "Y");
- Assert.AreEqual (16, bounds.Width, "Width");
- Assert.AreEqual (16, bounds.Height, "Height");
- Assert.IsTrue (g.Transform.IsIdentity, "Identity");
- g.Dispose ();
- }
- [Test]
- public void Clip_TranslateTransform ()
- {
- Graphics g = Get (16, 16);
- g.TranslateTransform (12.22f, 10.10f);
- RectangleF bounds = g.Clip.GetBounds (g);
- Compare ("translate", bounds, g.ClipBounds);
- Assert.AreEqual (-12.2200003f, bounds.X, "translate.X");
- Assert.AreEqual (-10.1000004f, bounds.Y, "translate.Y");
- Assert.AreEqual (16, bounds.Width, "translate.Width");
- Assert.AreEqual (16, bounds.Height, "translate.Height");
- float[] elements = g.Transform.Elements;
- Assert.AreEqual (1, elements[0], "translate.0");
- Assert.AreEqual (0, elements[1], "translate.1");
- Assert.AreEqual (0, elements[2], "translate.2");
- Assert.AreEqual (1, elements[3], "translate.3");
- Assert.AreEqual (12.2200003f, elements[4], "translate.4");
- Assert.AreEqual (10.1000004f, elements[5], "translate.5");
- g.ResetTransform ();
- bounds = g.Clip.GetBounds (g);
- Compare ("reset", bounds, g.ClipBounds);
- Assert.AreEqual (0, bounds.X, "reset.X");
- Assert.AreEqual (0, bounds.Y, "reset.Y");
- Assert.AreEqual (16, bounds.Width, "reset.Width");
- Assert.AreEqual (16, bounds.Height, "reset.Height");
- Assert.IsTrue (g.Transform.IsIdentity, "Identity");
- g.Dispose ();
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void Transform_NonInvertibleMatrix ()
- {
- Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
- Assert.IsFalse (matrix.IsInvertible, "IsInvertible");
- Graphics g = Get (16, 16);
- g.Transform = matrix;
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void Multiply_NonInvertibleMatrix ()
- {
- Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
- Assert.IsFalse (matrix.IsInvertible, "IsInvertible");
- Graphics g = Get (16, 16);
- g.MultiplyTransform (matrix);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Multiply_Null ()
- {
- Graphics g = Get (16, 16);
- g.MultiplyTransform (null);
- }
- private void CheckBounds (string msg, RectangleF bounds, float x, float y, float w, float h)
- {
- AssertEquals (msg + ".X", x, bounds.X, 0.1);
- AssertEquals (msg + ".Y", y, bounds.Y, 0.1);
- AssertEquals (msg + ".Width", w, bounds.Width, 0.1);
- AssertEquals (msg + ".Height", h, bounds.Height, 0.1);
- }
- [Test]
- public void ClipBounds ()
- {
- Graphics g = Get (16, 16);
- CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
- CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- CheckBounds ("clip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
- CheckBounds ("clip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- }
- [Test]
- public void ClipBounds_Rotate ()
- {
- Graphics g = Get (16, 16);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- g.RotateTransform (90);
- CheckBounds ("rotate.ClipBounds", g.ClipBounds, 0, -8, 8, 8);
- CheckBounds ("rotate.Clip.GetBounds", g.Clip.GetBounds (g), 0, -8, 8, 8);
- g.Transform = new Matrix ();
- CheckBounds ("identity.ClipBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- CheckBounds ("identity.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- }
- [Test]
- public void ClipBounds_Scale ()
- {
- RectangleF clip = new Rectangle (0, 0, 8, 8);
- Graphics g = Get (16, 16);
- g.Clip = new Region (clip);
- g.ScaleTransform (0.25f, 0.5f);
- CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 32, 16);
- CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 32, 16);
- g.SetClip (clip);
- CheckBounds ("setclip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
- CheckBounds ("setclip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- }
- [Test]
- public void ClipBounds_Translate ()
- {
- Graphics g = Get (16, 16);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- Region clone = g.Clip.Clone ();
- g.TranslateTransform (8, 8);
- CheckBounds ("translate.ClipBounds", g.ClipBounds, -8, -8, 8, 8);
- CheckBounds ("translate.Clip.GetBounds", g.Clip.GetBounds (g), -8, -8, 8, 8);
- g.SetClip (clone, CombineMode.Replace);
- CheckBounds ("setclip.ClipBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- CheckBounds ("setclip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- }
- [Test]
- public void ClipBounds_Transform_Translation ()
- {
- Graphics g = Get (16, 16);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- g.Transform = new Matrix (1, 0, 0, 1, 8, 8);
- CheckBounds ("transform.ClipBounds", g.ClipBounds, -8, -8, 8, 8);
- CheckBounds ("transform.Clip.GetBounds", g.Clip.GetBounds (g), -8, -8, 8, 8);
- g.ResetTransform ();
- CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
- CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- }
- [Test]
- public void ClipBounds_Transform_Scale ()
- {
- Graphics g = Get (16, 16);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- g.Transform = new Matrix (0.5f, 0, 0, 0.25f, 0, 0);
- CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 16, 32);
- CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 32);
- g.ResetClip ();
- // see next test for ClipBounds
- CheckBounds ("resetclip.Clip.GetBounds", g.Clip.GetBounds (g), -4194304, -4194304, 8388608, 8388608);
- Assert.IsTrue (g.Clip.IsInfinite (g), "IsInfinite");
- }
- [Test]
- [Category ("NotWorking")]
- public void ClipBounds_Transform_Scale_Strange ()
- {
- Graphics g = Get (16, 16);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- g.Transform = new Matrix (0.5f, 0, 0, 0.25f, 0, 0);
- CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 16, 32);
- CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 32);
- g.ResetClip ();
- // note: strange case where g.ClipBounds and g.Clip.GetBounds are different
- CheckBounds ("resetclip.ClipBounds", g.ClipBounds, -8388608, -16777216, 16777216, 33554432);
- }
- [Test]
- public void ClipBounds_Multiply ()
- {
- Graphics g = Get (16, 16);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- g.Transform = new Matrix (1, 0, 0, 1, 8, 8);
- g.MultiplyTransform (g.Transform);
- CheckBounds ("multiply.ClipBounds", g.ClipBounds, -16, -16, 8, 8);
- CheckBounds ("multiply.Clip.GetBounds", g.Clip.GetBounds (g), -16, -16, 8, 8);
- g.ResetTransform ();
- CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
- CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- }
- [Test]
- public void ClipBounds_Cumulative_Effects ()
- {
- Graphics g = Get (16, 16);
- CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
- CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- CheckBounds ("clip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
- CheckBounds ("clip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- g.RotateTransform (90);
- CheckBounds ("rotate.ClipBounds", g.ClipBounds, 0, -8, 8, 8);
- CheckBounds ("rotate.Clip.GetBounds", g.Clip.GetBounds (g), 0, -8, 8, 8);
- g.ScaleTransform (0.25f, 0.5f);
- CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, -16, 32, 16);
- CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, -16, 32, 16);
- g.TranslateTransform (8, 8);
- CheckBounds ("translate.ClipBounds", g.ClipBounds, -8, -24, 32, 16);
- CheckBounds ("translate.Clip.GetBounds", g.Clip.GetBounds (g), -8, -24, 32, 16);
- g.MultiplyTransform (g.Transform);
- CheckBounds ("multiply.ClipBounds", g.ClipBounds, -104, -56, 64, 64);
- CheckBounds ("multiply.Clip.GetBounds", g.Clip.GetBounds (g), -104, -56, 64, 64);
- g.ResetTransform ();
- CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
- CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- }
- [Test]
- public void Clip_TranslateTransform_BoundsChange ()
- {
- Graphics g = Get (16, 16);
- CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
- CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
- g.TranslateTransform (-16, -16);
- CheckBounds ("translated.ClipBounds", g.ClipBounds, 16, 16, 16, 16);
- CheckBounds ("translated.Clip.GetBounds", g.Clip.GetBounds (g), 16, 16, 16, 16);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- // ClipBounds isn't affected by a previous translation
- CheckBounds ("rectangle.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
- // Clip.GetBounds isn't affected by a previous translation
- CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- g.ResetTransform ();
- CheckBounds ("reseted.ClipBounds", g.ClipBounds, -16, -16, 8, 8);
- CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -16, -16, 8, 8);
- }
- [Test]
- public void Clip_RotateTransform_BoundsChange ()
- {
- Graphics g = Get (16, 16);
- CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
- CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
- // we select a "simple" angle because the region will be converted into
- // a bitmap (well for libgdiplus) and we would lose precision after that
- g.RotateTransform (90);
- CheckBounds ("rotated.ClipBounds", g.ClipBounds, 0, -16, 16, 16);
- CheckBounds ("rotated.Clip.GetBounds", g.Clip.GetBounds (g), 0, -16, 16, 16);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- // ClipBounds isn't affected by a previous rotation (90)
- CheckBounds ("rectangle.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
- // Clip.GetBounds isn't affected by a previous rotation
- CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- g.ResetTransform ();
- CheckBounds ("reseted.ClipBounds", g.ClipBounds, -8, 0, 8, 8);
- CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -8, 0, 8, 8);
- }
- private void CheckBoundsInt (string msg, RectangleF bounds, int x, int y, int w, int h)
- {
- // currently bounds are rounded at 8 pixels (FIXME - we can go down to 1 pixel)
- AssertEquals (msg + ".X", x, bounds.X, 4f);
- AssertEquals (msg + ".Y", y, bounds.Y, 4f);
- AssertEquals (msg + ".Width", w, bounds.Width, 4f);
- AssertEquals (msg + ".Height", h, bounds.Height, 4f);
- }
- [Test]
- [Category ("NotWorking")]
- public void Clip_RotateTransform_BoundsChange_45 ()
- {
- Graphics g = Get (16, 16);
- CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
- CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
- g.RotateTransform (45);
- // we can't use the "normal" CheckBound here because of libgdiplus crude rounding
- CheckBoundsInt ("rotated.ClipBounds", g.ClipBounds, 0, -11, 24, 24);
- CheckBoundsInt ("rotated.Clip.GetBounds", g.Clip.GetBounds (g), 0, -11, 24, 24);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- // ClipBounds IS affected by a previous rotation (45)
- CheckBoundsInt ("rectangle.ClipBounds", g.ClipBounds, -3, -4, 16, 16);
- // Clip.GetBounds isn't affected by a previous rotation
- CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- g.ResetTransform ();
- CheckBounds ("reseted.ClipBounds", g.ClipBounds, -5, 1, 11, 11);
- CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -5.6f, 0, 11.3f, 11.3f);
- }
- [Test]
- public void Clip_ScaleTransform_NoBoundsChange ()
- {
- Graphics g = Get (16, 16);
- CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
- CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
- g.ScaleTransform (2, 0.5f);
- CheckBounds ("scaled.ClipBounds", g.ClipBounds, 0, 0, 8, 32);
- CheckBounds ("scaled.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 32);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- // ClipBounds isn't affected by a previous scaling
- CheckBounds ("rectangle.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
- // Clip.GetBounds isn't affected by a previous scaling
- CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- g.ResetTransform ();
- CheckBounds ("reseted.ClipBounds", g.ClipBounds, 0, 0, 16, 4);
- CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 4);
- }
- [Test]
- [Category ("NotWorking")]
- public void Clip_MultiplyTransform_NoBoundsChange ()
- {
- Graphics g = Get (16, 16);
- CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
- CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
- g.MultiplyTransform (new Matrix (2.5f, 0.5f, -2.5f, 0.5f, 4, -4));
- CheckBounds ("multiplied.ClipBounds", g.ClipBounds, 3.2f, 1.6f, 19.2f, 19.2f);
- CheckBounds ("multiplied.Clip.GetBounds", g.Clip.GetBounds (g), 3.2f, 1.6f, 19.2f, 19.2f);
- g.Clip = new Region (new Rectangle (0, 0, 8, 8));
- // ClipBounds IS affected by the previous multiplication
- CheckBounds ("rectangle.ClipBounds", g.ClipBounds, -3, -3, 15, 15);
- // Clip.GetBounds isn't affected by the previous multiplication
- CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
- g.ResetTransform ();
- CheckBounds ("reseted.ClipBounds", g.ClipBounds, -16, -3, 40, 7);
- CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -16, -4, 40, 8);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void ScaleTransform_X0 ()
- {
- Graphics g = Get (16, 16);
- g.ScaleTransform (0, 1);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void ScaleTransform_Y0 ()
- {
- Graphics g = Get (16, 16);
- g.ScaleTransform (1, 0);
- }
- [Test]
- public void TranslateTransform_Order ()
- {
- Graphics g = Get (16, 16);
- g.Transform = new Matrix (1, 2, 3, 4, 5, 6);
- g.TranslateTransform (3, -3);
- float[] elements = g.Transform.Elements;
- Assert.AreEqual (1, elements[0], "default.0");
- Assert.AreEqual (2, elements[1], "default.1");
- Assert.AreEqual (3, elements[2], "default.2");
- Assert.AreEqual (4, elements[3], "default.3");
- Assert.AreEqual (-1, elements[4], "default.4");
- Assert.AreEqual (0, elements[5], "default.5");
- g.Transform = new Matrix (1, 2, 3, 4, 5, 6);
- g.TranslateTransform (3, -3, MatrixOrder.Prepend);
- elements = g.Transform.Elements;
- Assert.AreEqual (1, elements[0], "prepend.0");
- Assert.AreEqual (2, elements[1], "prepend.1");
- Assert.AreEqual (3, elements[2], "prepend.2");
- Assert.AreEqual (4, elements[3], "prepend.3");
- Assert.AreEqual (-1, elements[4], "prepend.4");
- Assert.AreEqual (0, elements[5], "prepend.5");
- g.Transform = new Matrix (1, 2, 3, 4, 5, 6);
- g.TranslateTransform (3, -3, MatrixOrder.Append);
- elements = g.Transform.Elements;
- Assert.AreEqual (1, elements[0], "append.0");
- Assert.AreEqual (2, elements[1], "append.1");
- Assert.AreEqual (3, elements[2], "append.2");
- Assert.AreEqual (4, elements[3], "append.3");
- Assert.AreEqual (8, elements[4], "append.4");
- Assert.AreEqual (3, elements[5], "append.5");
- }
- static Point[] SmallCurve = new Point[3] { new Point (0, 0), new Point (15, 5), new Point (5, 15) };
- static PointF[] SmallCurveF = new PointF[3] { new PointF (0, 0), new PointF (15, 5), new PointF (5, 15) };
- static Point[] TooSmallCurve = new Point[2] { new Point (0, 0), new Point (15, 5) };
- static PointF[] LargeCurveF = new PointF[4] { new PointF (0, 0), new PointF (15, 5), new PointF (5, 15), new PointF (0, 20) };
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawCurve_PenNull ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (null, SmallCurveF);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawCurve_PointFNull ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (Pens.Black, (PointF[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawCurve_PointNull ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (Pens.Black, (Point[]) null);
- }
- [Test]
- public void DrawCurve_NotEnoughPoints ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- CheckForEmptyBitmap (bitmap);
- g.DrawCurve (Pens.Black, TooSmallCurve, 0.5f);
- CheckForNonEmptyBitmap (bitmap);
- // so a "curve" can be drawn with less than 3 points!
- // actually I used to call that a line... (and it's not related to tension)
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawCurve_SinglePoint ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (Pens.Black, new Point[1] { new Point (10, 10) }, 0.5f);
- // a single point isn't enough
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawCurve3_NotEnoughPoints ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (Pens.Black, TooSmallCurve, 0, 2, 0.5f);
- // aha, this is API dependent
- }
- [Test]
- public void DrawCurve_NegativeTension ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- // documented as bigger (or equals) to 0
- g.DrawCurve (Pens.Black, SmallCurveF, -0.9f);
- CheckForNonEmptyBitmap (bitmap);
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test]
- public void DrawCurve_PositiveTension ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (Pens.Black, SmallCurveF, 0.9f);
- // this is not the same as -1
- CheckForNonEmptyBitmap (bitmap);
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test]
- [Category ("NotWorking")] // libgdiplus is drawing something
- public void DrawCurve_LargeTension ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (Pens.Black, SmallCurve, Single.MaxValue);
- CheckForEmptyBitmap (bitmap);
- // too much tension ;)
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawCurve_ZeroSegments ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (Pens.Black, SmallCurveF, 0, 0);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawCurve_NegativeSegments ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (Pens.Black, SmallCurveF, 0, -1);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawCurve_OffsetTooLarge ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- // starting offset 1 doesn't give 3 points to make a curve
- g.DrawCurve (Pens.Black, SmallCurveF, 1, 2);
- // and in this case 2 points aren't enough to draw something
- }
- [Test]
- public void DrawCurve_Offset_0 ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (Pens.Black, LargeCurveF, 0, 2, 0.5f);
- CheckForNonEmptyBitmap (bitmap);
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test]
- public void DrawCurve_Offset_1 ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.DrawCurve (Pens.Black, LargeCurveF, 1, 2, 0.5f);
- CheckForNonEmptyBitmap (bitmap);
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test]
- public void DrawCurve_Offset_2 ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- // it works even with two points because we know the previous ones
- g.DrawCurve (Pens.Black, LargeCurveF, 2, 1, 0.5f);
- CheckForNonEmptyBitmap (bitmap);
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test]
- public void DrawRectangle_Negative ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- Pen pen = new Pen (Color.Red);
- g.DrawRectangle (pen, 5, 5, -10, -10);
- g.DrawRectangle (pen, 0.0f, 0.0f, 5.0f, -10.0f);
- g.DrawRectangle (pen, new Rectangle (15, 0, -10, 5));
- CheckForEmptyBitmap (bitmap);
- pen.Dispose ();
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test]
- public void DrawRectangles_Negative ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- Pen pen = new Pen (Color.Red);
- Rectangle[] rects = new Rectangle[2] {
- new Rectangle (5, 5, -10, -10), new Rectangle (0, 0, 5, -10)
- };
- RectangleF[] rectf = new RectangleF[2] {
- new RectangleF (0.0f, 5.0f, -10.0f, -10.0f), new RectangleF (15.0f, 0.0f, -10.0f, 5.0f)
- };
- g.DrawRectangles (pen, rects);
- g.DrawRectangles (pen, rectf);
- CheckForEmptyBitmap (bitmap);
- pen.Dispose ();
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test]
- public void FillRectangle_Negative ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- SolidBrush brush = new SolidBrush (Color.Red);
- g.FillRectangle (brush, 5, 5, -10, -10);
- g.FillRectangle (brush, 0.0f, 0.0f, 5.0f, -10.0f);
- g.FillRectangle (brush, new Rectangle (15, 0, -10, 5));
- CheckForEmptyBitmap (bitmap);
- brush.Dispose ();
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test]
- public void FillRectangles_Negative ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- SolidBrush brush = new SolidBrush (Color.Red);
- Rectangle[] rects = new Rectangle[2] {
- new Rectangle (5, 5, -10, -10), new Rectangle (0, 0, 5, -10)
- };
- RectangleF[] rectf = new RectangleF[2] {
- new RectangleF (0.0f, 5.0f, -10.0f, -10.0f), new RectangleF (15.0f, 0.0f, -10.0f, 5.0f)
- };
- g.FillRectangles (brush, rects);
- g.FillRectangles (brush, rectf);
- CheckForEmptyBitmap (bitmap);
- brush.Dispose ();
- g.Dispose ();
- bitmap.Dispose ();
- }
- [Test] // bug #355141
- [Category ("CAS")]
- public void FromHwnd_Zero ()
- {
- Graphics g = Graphics.FromHwnd (IntPtr.Zero);
- Assert.IsNotNull (g);
- }
- private void CheckDefaultProperties (string message, Graphics g)
- {
- Assert.IsTrue (g.Clip.IsInfinite (g), message + ".Clip.IsInfinite");
- AssertEquals (message + ".CompositingMode", CompositingMode.SourceOver, g.CompositingMode);
- AssertEquals (message + ".CompositingQuality", CompositingQuality.Default, g.CompositingQuality);
- AssertEquals (message + ".InterpolationMode", InterpolationMode.Bilinear, g.InterpolationMode);
- AssertEquals (message + ".PageScale", 1.0f, g.PageScale);
- AssertEquals (message + ".PageUnit", GraphicsUnit.Display, g.PageUnit);
- AssertEquals (message + ".PixelOffsetMode", PixelOffsetMode.Default, g.PixelOffsetMode);
- AssertEquals (message + ".SmoothingMode", SmoothingMode.None, g.SmoothingMode);
- AssertEquals (message + ".TextContrast", 4, g.TextContrast);
- AssertEquals (message + ".TextRenderingHint", TextRenderingHint.SystemDefault, g.TextRenderingHint);
- Assert.IsTrue (g.Transform.IsIdentity, message + ".Transform.IsIdentity");
- }
- private void CheckCustomProperties (string message, Graphics g)
- {
- Assert.IsFalse (g.Clip.IsInfinite (g), message + ".Clip.IsInfinite");
- AssertEquals (message + ".CompositingMode", CompositingMode.SourceCopy, g.CompositingMode);
- AssertEquals (message + ".CompositingQuality", CompositingQuality.HighQuality, g.CompositingQuality);
- AssertEquals (message + ".InterpolationMode", InterpolationMode.HighQualityBicubic, g.InterpolationMode);
- AssertEquals (message + ".PageScale", 0.5f, g.PageScale);
- AssertEquals (message + ".PageUnit", GraphicsUnit.Inch, g.PageUnit);
- AssertEquals (message + ".PixelOffsetMode", PixelOffsetMode.Half, g.PixelOffsetMode);
- AssertEquals (message + ".RenderingOrigin", new Point (-1, -1), g.RenderingOrigin);
- AssertEquals (message + ".SmoothingMode", SmoothingMode.AntiAlias, g.SmoothingMode);
- AssertEquals (message + ".TextContrast", 0, g.TextContrast);
- AssertEquals (message + ".TextRenderingHint", TextRenderingHint.AntiAlias, g.TextRenderingHint);
- Assert.IsFalse (g.Transform.IsIdentity, message + ".Transform.IsIdentity");
- }
- private void CheckMatrix (string message, Matrix m, float xx, float yx, float xy, float yy, float x0, float y0)
- {
- float[] elements = m.Elements;
- AssertEquals (message + ".Matrix.xx", xx, elements[0], 0.01);
- AssertEquals (message + ".Matrix.yx", yx, elements[1], 0.01);
- AssertEquals (message + ".Matrix.xy", xy, elements[2], 0.01);
- AssertEquals (message + ".Matrix.yy", yy, elements[3], 0.01);
- AssertEquals (message + ".Matrix.x0", x0, elements[4], 0.01);
- AssertEquals (message + ".Matrix.y0", y0, elements[5], 0.01);
- }
- [Test]
- public void BeginContainer ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- CheckDefaultProperties ("default", g);
- Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
- g.Clip = new Region (new Rectangle (10, 10, 10, 10));
- g.CompositingMode = CompositingMode.SourceCopy;
- g.CompositingQuality = CompositingQuality.HighQuality;
- g.InterpolationMode = InterpolationMode.HighQualityBicubic;
- g.PageScale = 0.5f;
- g.PageUnit = GraphicsUnit.Inch;
- g.PixelOffsetMode = PixelOffsetMode.Half;
- g.RenderingOrigin = new Point (-1, -1);
- g.RotateTransform (45);
- g.SmoothingMode = SmoothingMode.AntiAlias;
- g.TextContrast = 0;
- g.TextRenderingHint = TextRenderingHint.AntiAlias;
- CheckCustomProperties ("modified", g);
- CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
- GraphicsContainer gc = g.BeginContainer ();
- // things gets reseted after calling BeginContainer
- CheckDefaultProperties ("BeginContainer", g);
- // but not everything
- Assert.AreEqual (new Point (-1, -1), g.RenderingOrigin, "BeginContainer.RenderingOrigin");
- g.EndContainer (gc);
- CheckCustomProperties ("EndContainer", g);
- }
- [Test]
- public void BeginContainer_Rect ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- CheckDefaultProperties ("default", g);
- Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
- g.Clip = new Region (new Rectangle (10, 10, 10, 10));
- g.CompositingMode = CompositingMode.SourceCopy;
- g.CompositingQuality = CompositingQuality.HighQuality;
- g.InterpolationMode = InterpolationMode.HighQualityBicubic;
- g.PageScale = 0.5f;
- g.PageUnit = GraphicsUnit.Inch;
- g.PixelOffsetMode = PixelOffsetMode.Half;
- g.RenderingOrigin = new Point (-1, -1);
- g.RotateTransform (45);
- g.SmoothingMode = SmoothingMode.AntiAlias;
- g.TextContrast = 0;
- g.TextRenderingHint = TextRenderingHint.AntiAlias;
- CheckCustomProperties ("modified", g);
- CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
- GraphicsContainer gc = g.BeginContainer (new Rectangle (10, 20, 30, 40), new Rectangle (10, 20, 300, 400), GraphicsUnit.Millimeter);
- // things gets reseted after calling BeginContainer
- CheckDefaultProperties ("BeginContainer", g);
- // but not everything
- Assert.AreEqual (new Point (-1, -1), g.RenderingOrigin, "BeginContainer.RenderingOrigin");
- g.EndContainer (gc);
- CheckCustomProperties ("EndContainer", g);
- CheckMatrix ("EndContainer.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
- }
- [Test]
- public void BeginContainer_RectF ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- CheckDefaultProperties ("default", g);
- Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
- g.Clip = new Region (new Rectangle (10, 10, 10, 10));
- g.CompositingMode = CompositingMode.SourceCopy;
- g.CompositingQuality = CompositingQuality.HighQuality;
- g.InterpolationMode = InterpolationMode.HighQualityBicubic;
- g.PageScale = 0.5f;
- g.PageUnit = GraphicsUnit.Inch;
- g.PixelOffsetMode = PixelOffsetMode.Half;
- g.RenderingOrigin = new Point (-1, -1);
- g.RotateTransform (45);
- g.SmoothingMode = SmoothingMode.AntiAlias;
- g.TextContrast = 0;
- g.TextRenderingHint = TextRenderingHint.AntiAlias;
- CheckCustomProperties ("modified", g);
- CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
- GraphicsContainer gc = g.BeginContainer (new RectangleF (40, 30, 20, 10), new RectangleF (10, 20, 30, 40), GraphicsUnit.Inch);
- // things gets reseted after calling BeginContainer
- CheckDefaultProperties ("BeginContainer", g);
- // but not everything
- Assert.AreEqual (new Point (-1, -1), g.RenderingOrigin, "BeginContainer.RenderingOrigin");
- g.EndContainer (gc);
- CheckCustomProperties ("EndContainer", g);
- }
- private void BeginContainer_GraphicsUnit (GraphicsUnit unit)
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.BeginContainer (new RectangleF (40, 30, 20, 10), new RectangleF (10, 20, 30, 40), unit);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void BeginContainer_GraphicsUnit_Display ()
- {
- BeginContainer_GraphicsUnit (GraphicsUnit.Display);
- }
- [Test]
- public void BeginContainer_GraphicsUnit_Valid ()
- {
- BeginContainer_GraphicsUnit (GraphicsUnit.Document);
- BeginContainer_GraphicsUnit (GraphicsUnit.Inch);
- BeginContainer_GraphicsUnit (GraphicsUnit.Millimeter);
- BeginContainer_GraphicsUnit (GraphicsUnit.Pixel);
- BeginContainer_GraphicsUnit (GraphicsUnit.Point);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void BeginContainer_GraphicsUnit_World ()
- {
- BeginContainer_GraphicsUnit (GraphicsUnit.World);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void BeginContainer_GraphicsUnit_Bad ()
- {
- BeginContainer_GraphicsUnit ((GraphicsUnit) Int32.MinValue);
- }
- [Test]
- #if NET_2_0
- [ExpectedException (typeof (ArgumentNullException))]
- #else
- [ExpectedException (typeof (NullReferenceException))]
- #endif
- public void EndContainer_Null ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.EndContainer (null);
- }
- [Test]
- public void Save ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- CheckDefaultProperties ("default", g);
- Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
- GraphicsState gs1 = g.Save ();
- // nothing is changed after a save
- CheckDefaultProperties ("save1", g);
- Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "save1.RenderingOrigin");
- g.Clip = new Region (new Rectangle (10, 10, 10, 10));
- g.CompositingMode = CompositingMode.SourceCopy;
- g.CompositingQuality = CompositingQuality.HighQuality;
- g.InterpolationMode = InterpolationMode.HighQualityBicubic;
- g.PageScale = 0.5f;
- g.PageUnit = GraphicsUnit.Inch;
- g.PixelOffsetMode = PixelOffsetMode.Half;
- g.RenderingOrigin = new Point (-1, -1);
- g.RotateTransform (45);
- g.SmoothingMode = SmoothingMode.AntiAlias;
- g.TextContrast = 0;
- g.TextRenderingHint = TextRenderingHint.AntiAlias;
- CheckCustomProperties ("modified", g);
- CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
- GraphicsState gs2 = g.Save ();
- CheckCustomProperties ("save2", g);
- g.Restore (gs2);
- CheckCustomProperties ("restored1", g);
- CheckMatrix ("restored1.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
- g.Restore (gs1);
- CheckDefaultProperties ("restored2", g);
- Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "restored2.RenderingOrigin");
- }
- [Test]
- [ExpectedException (typeof (NullReferenceException))]
- public void Restore_Null ()
- {
- Bitmap bitmap = new Bitmap (20, 20);
- Graphics g = Graphics.FromImage (bitmap);
- g.Restore (null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void FillRectangles_BrushNull_Rectangle ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.FillRectangles (null, new Rectangle[1]);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void FillRectangles_Rectangle_Null ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.FillRectangles (Brushes.Red, (Rectangle[]) null);
- }
- }
- }
- [Test] // see bug #78408
- [ExpectedException (typeof (ArgumentException))]
- public void FillRectanglesZeroRectangle ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.FillRectangles (Brushes.Red, new Rectangle[0]);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void FillRectangles_BrushNull_RectangleF ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.FillRectangles (null, new RectangleF[1]);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void FillRectangles_RectangleF_Null ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.FillRectangles (Brushes.Red, (RectangleF[]) null);
- }
- }
- }
- [Test] // see bug #78408
- [ExpectedException (typeof (ArgumentException))]
- public void FillRectanglesZeroRectangleF ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.FillRectangles (Brushes.Red, new RectangleF[0]);
- }
- }
- }
- [Test]
- public void FillRectangles_NormalBehavior ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.Clear (Color.Fuchsia);
- Rectangle rect = new Rectangle (5, 5, 10, 10);
- g.Clip = new Region (rect);
- g.FillRectangle (Brushes.Red, rect);
- }
- Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (5, 5).ToArgb (), "5,5");
- Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (14, 5).ToArgb (), "14,5");
- Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (5, 14).ToArgb (), "5,14");
- Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (14, 14).ToArgb (), "14,14");
- Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (15, 5).ToArgb (), "15,5");
- Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (5, 15).ToArgb (), "5,15");
- Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (15, 15).ToArgb (), "15,15");
- }
- }
- // see bug #81737 for details
- private Bitmap FillDrawRectangle (float width)
- {
- Bitmap bitmap = new Bitmap (20, 20);
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.Clear (Color.Red);
- Rectangle rect = new Rectangle (5, 5, 10, 10);
- g.FillRectangle (Brushes.Green, rect);
- if (width >= 0) {
- using (Pen pen = new Pen (Color.Blue, width)) {
- g.DrawRectangle (pen, rect);
- }
- } else {
- g.DrawRectangle (Pens.Blue, rect);
- }
- }
- return bitmap;
- }
- [Test]
- public void FillDrawRectangle_Width_Default ()
- {
- // default pen size
- using (Bitmap bitmap = FillDrawRectangle (Single.MinValue)) {
- // NW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
- // N
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
- // NE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
- // E
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
- // SE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
- // S
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
- // SW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
- // W
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
- }
- }
- [Test]
- [Category ("NotOnMac")]
- public void FillDrawRectangle_Width_2 ()
- {
- // even pen size
- using (Bitmap bitmap = FillDrawRectangle (2.0f)) {
- // NW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
- // N
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
- // NE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
- // E
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 9).ToArgb (), "13,9");
- // SE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 13).ToArgb (), "13,13");
- // S
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 13).ToArgb (), "9,13");
- // SW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 16).ToArgb (), "3,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 15).ToArgb (), "4,15");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 14).ToArgb (), "5,14");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 13).ToArgb (), "6,13");
- // W
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
- }
- }
- [Test]
- public void FillDrawRectangle_Width_3 ()
- {
- // odd pen size
- using (Bitmap bitmap = FillDrawRectangle (3.0f)) {
- // NW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 7).ToArgb (), "7,7");
- // N
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 7).ToArgb (), "9,7");
- // NE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 7).ToArgb (), "13,7");
- // E
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 9).ToArgb (), "17,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 9).ToArgb (), "13,9");
- // SE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 17).ToArgb (), "17,17");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 13).ToArgb (), "13,13");
- // S
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 17).ToArgb (), "9,17");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 13).ToArgb (), "9,13");
- // SW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 17).ToArgb (), "3,17");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 13).ToArgb (), "7,13");
- // W
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 9).ToArgb (), "7,9");
- }
- }
- // reverse, draw the fill over
- private Bitmap DrawFillRectangle (float width)
- {
- Bitmap bitmap = new Bitmap (20, 20);
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.Clear (Color.Red);
- Rectangle rect = new Rectangle (5, 5, 10, 10);
- if (width >= 0) {
- using (Pen pen = new Pen (Color.Blue, width)) {
- g.DrawRectangle (pen, rect);
- }
- } else {
- g.DrawRectangle (Pens.Blue, rect);
- }
- g.FillRectangle (Brushes.Green, rect);
- }
- return bitmap;
- }
- [Test]
- public void DrawFillRectangle_Width_Default ()
- {
- // default pen size
- using (Bitmap bitmap = DrawFillRectangle (Single.MinValue)) {
- // NW - no blue border
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
- // N - no blue border
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
- // NE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
- // E
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
- // SE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
- // S
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
- // SW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
- // W - no blue border
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
- }
- }
- [Test]
- [Category ("NotOnMac")]
- public void DrawFillRectangle_Width_2 ()
- {
- // even pen size
- using (Bitmap bitmap = DrawFillRectangle (2.0f)) {
- // looks like a one pixel border - but enlarged
- // NW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
- // N
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
- // NE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
- // E
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
- // SE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
- // S
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
- // SW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 16).ToArgb (), "4,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 15).ToArgb (), "5,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 14).ToArgb (), "6,14");
- // W
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
- }
- }
- [Test]
- public void DrawFillRectangle_Width_3 ()
- {
- // odd pen size
- using (Bitmap bitmap = DrawFillRectangle (3.0f)) {
- // NW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
- // N
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
- // NE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
- // E
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 9).ToArgb (), "17,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
- // SE
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 17).ToArgb (), "17,17");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
- // S
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 17).ToArgb (), "9,17");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
- // SW
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 17).ToArgb (), "3,17");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
- // W
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
- Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
- }
- }
- private Bitmap DrawLines (float width)
- {
- Bitmap bitmap = new Bitmap (20, 20);
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.Clear (Color.Red);
- Point[] pts = new Point[3] { new Point (5, 5), new Point (15, 5), new Point (15, 15) };
- if (width >= 0) {
- using (Pen pen = new Pen (Color.Blue, width)) {
- g.DrawLines (pen, pts);
- }
- } else {
- g.DrawLines (Pens.Blue, pts);
- }
- }
- return bitmap;
- }
- [Test]
- public void DrawLines_Width_Default ()
- {
- // default pen size
- using (Bitmap bitmap = DrawLines (Single.MinValue)) {
- // start
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
- // middle
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
- //end
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 16).ToArgb (), "14,16");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 16).ToArgb (), "15,16");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
- }
- }
- [Test]
- [Category ("NotWorking")]
- public void DrawLines_Width_2 ()
- {
- // default pen size
- using (Bitmap bitmap = DrawLines (2.0f)) {
- // start
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 3).ToArgb (), "4,3");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 3).ToArgb (), "5,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
- // middle
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 3).ToArgb (), "13,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 4).ToArgb (), "13,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 5).ToArgb (), "13,5");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 3).ToArgb (), "14,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 3).ToArgb (), "15,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
- //end
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 14).ToArgb (), "13,14");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 14).ToArgb (), "15,14");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 14).ToArgb (), "16,14");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 15).ToArgb (), "13,15");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
- }
- }
- [Test]
- [Category ("NotWorking")]
- public void DrawLines_Width_3 ()
- {
- // default pen size
- using (Bitmap bitmap = DrawLines (3.0f)) {
- // start
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 3).ToArgb (), "4,3");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 7).ToArgb (), "4,7");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 3).ToArgb (), "5,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 7).ToArgb (), "5,7");
- // middle
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 3).ToArgb (), "13,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 4).ToArgb (), "13,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 5).ToArgb (), "13,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 7).ToArgb (), "13,7");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 3).ToArgb (), "14,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 7).ToArgb (), "14,7");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 3).ToArgb (), "15,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 7).ToArgb (), "15,7");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 7).ToArgb (), "16,7");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 4).ToArgb (), "17,4");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 5).ToArgb (), "17,5");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 6).ToArgb (), "17,6");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 7).ToArgb (), "17,7");
- //end
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 14).ToArgb (), "13,14");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 14).ToArgb (), "15,14");
- Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 14).ToArgb (), "16,14");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 14).ToArgb (), "17,14");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 15).ToArgb (), "13,15");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
- Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 15).ToArgb (), "17,15");
- }
- }
- [Test]
- public void MeasureString_StringFont ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- SizeF size = g.MeasureString (null, font);
- Assert.IsTrue (size.IsEmpty, "MeasureString(null,font)");
- size = g.MeasureString (String.Empty, font);
- Assert.IsTrue (size.IsEmpty, "MeasureString(empty,font)");
- // null font
- size = g.MeasureString (null, null);
- Assert.IsTrue (size.IsEmpty, "MeasureString(null,null)");
- size = g.MeasureString (String.Empty, null);
- Assert.IsTrue (size.IsEmpty, "MeasureString(empty,null)");
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void MeasureString_StringFont_Null ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.MeasureString ("a", null);
- }
- }
- }
- [Test]
- public void MeasureString_StringFontSizeF ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- SizeF size = g.MeasureString ("a", font, SizeF.Empty);
- Assert.IsFalse (size.IsEmpty, "MeasureString(a,font,empty)");
- size = g.MeasureString (String.Empty, font, SizeF.Empty);
- Assert.IsTrue (size.IsEmpty, "MeasureString(empty,font,empty)");
- }
- }
- }
- private void MeasureString_StringFontInt (string s)
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- SizeF size0 = g.MeasureString (s, font, 0);
- SizeF sizeN = g.MeasureString (s, font, Int32.MinValue);
- SizeF sizeP = g.MeasureString (s, font, Int32.MaxValue);
- Assert.AreEqual (size0, sizeN, "0-Min");
- Assert.AreEqual (size0, sizeP, "0-Max");
- }
- }
- }
- [Test]
- public void MeasureString_StringFontInt_ShortString ()
- {
- MeasureString_StringFontInt ("a");
- }
- [Test]
- public void MeasureString_StringFontInt_LongString ()
- {
- HostIgnoreList.CheckTest ("MonoTests.System.Drawing.GraphicsTest.MeasureString_StringFontInt_LongString");
- MeasureString_StringFontInt ("A very long string..."); // see bug #79643
- }
- [Test]
- public void MeasureString_StringFormat_Alignment ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "Hello Mono::";
- StringFormat string_format = new StringFormat ();
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- string_format.Alignment = StringAlignment.Near;
- SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
- string_format.Alignment = StringAlignment.Center;
- SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
- string_format.Alignment = StringAlignment.Far;
- SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
- Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
- Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
- Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
- Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
- }
- }
- }
- [Test]
- public void MeasureString_StringFormat_Alignment_DirectionVertical ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "Hello Mono::";
- StringFormat string_format = new StringFormat ();
- string_format.FormatFlags = StringFormatFlags.DirectionVertical;
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- string_format.Alignment = StringAlignment.Near;
- SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
- string_format.Alignment = StringAlignment.Center;
- SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
- string_format.Alignment = StringAlignment.Far;
- SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
- Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
- Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
- Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
- Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
- }
- }
- }
- [Test]
- public void MeasureString_StringFormat_LineAlignment ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "Hello Mono::";
- StringFormat string_format = new StringFormat ();
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- string_format.LineAlignment = StringAlignment.Near;
- SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
- string_format.LineAlignment = StringAlignment.Center;
- SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
- string_format.LineAlignment = StringAlignment.Far;
- SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
- Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
- Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
- Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
- Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
- }
- }
- }
- [Test]
- public void MeasureString_StringFormat_LineAlignment_DirectionVertical ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "Hello Mono::";
- StringFormat string_format = new StringFormat ();
- string_format.FormatFlags = StringFormatFlags.DirectionVertical;
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- string_format.LineAlignment = StringAlignment.Near;
- SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
- string_format.LineAlignment = StringAlignment.Center;
- SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
- string_format.LineAlignment = StringAlignment.Far;
- SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
- Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
- Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
- Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
- Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
- }
- }
- }
- [Test]
- public void MeasureString_MultlineString_Width ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- StringFormat string_format = new StringFormat ();
- string text1 = "Test\nTest123\nTest 456\nTest 1,2,3,4,5...";
- string text2 = "Test 1,2,3,4,5...";
- SizeF size1 = g.MeasureString (text1, font, SizeF.Empty, string_format);
- SizeF size2 = g.MeasureString (text2, font, SizeF.Empty, string_format);
- Assert.AreEqual ((int) size1.Width, (int) size2.Width, "Multiline Text Width");
- }
- }
- }
- [Test]
- public void MeasureString_Bug76664 ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- string s = "aaa aa aaaa a aaa";
- SizeF size = g.MeasureString (s, font);
- int chars, lines;
- SizeF size2 = g.MeasureString (s, font, new SizeF (80, size.Height), null, out chars, out lines);
- // in pixels
- Assert.IsTrue (size2.Width < size.Width, "Width/pixel");
- Assert.AreEqual (size2.Height, size.Height, "Height/pixel");
- Assert.AreEqual (1, lines, "lines fitted");
- // LAMESPEC: documentation seems to suggest chars is total length
- Assert.IsTrue (chars < s.Length, "characters fitted");
- }
- }
- }
- [Test]
- public void MeasureString_Bug80680 ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- string s = String.Empty;
- SizeF size = g.MeasureString (s, font);
- Assert.AreEqual (0, size.Height, "Empty.Height");
- Assert.AreEqual (0, size.Width, "Empty.Width");
- s += " ";
- SizeF expected = g.MeasureString (s, font);
- for (int i = 1; i < 10; i++) {
- s += " ";
- size = g.MeasureString (s, font);
- Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
- Assert.AreEqual (expected.Width, size.Width, 0.1, ">" + s + "< Width");
- }
- s = "a";
- expected = g.MeasureString (s, font);
- s = " " + s;
- size = g.MeasureString (s, font);
- float space_width = size.Width - expected.Width;
- for (int i = 1; i < 10; i++) {
- size = g.MeasureString (s, font);
- Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
- Assert.AreEqual (expected.Width + i * space_width, size.Width, 0.1, ">" + s + "< Width");
- s = " " + s;
- }
- s = "a";
- expected = g.MeasureString (s, font);
- for (int i = 1; i < 10; i++) {
- s = s + " ";
- size = g.MeasureString (s, font);
- Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
- Assert.AreEqual (expected.Width, size.Width, 0.1, ">" + s + "< Width");
- }
- }
- }
- }
- [Test]
- public void MeasureCharacterRanges_NullOrEmptyText ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- Region[] regions = g.MeasureCharacterRanges (null, font, new RectangleF (), null);
- Assert.AreEqual (0, regions.Length, "text null");
- regions = g.MeasureCharacterRanges (String.Empty, font, new RectangleF (), null);
- Assert.AreEqual (0, regions.Length, "text empty");
- // null font is ok with null or empty string
- regions = g.MeasureCharacterRanges (null, null, new RectangleF (), null);
- Assert.AreEqual (0, regions.Length, "text null/null font");
- regions = g.MeasureCharacterRanges (String.Empty, null, new RectangleF (), null);
- Assert.AreEqual (0, regions.Length, "text empty/null font");
- }
- }
- }
- [Test]
- public void MeasureCharacterRanges_EmptyStringFormat ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- // string format without character ranges
- Region[] regions = g.MeasureCharacterRanges ("Mono", font, new RectangleF (), new StringFormat ());
- Assert.AreEqual (0, regions.Length, "empty stringformat");
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void MeasureCharacterRanges_FontNull ()
- {
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.MeasureCharacterRanges ("a", null, new RectangleF (), null);
- }
- }
- }
- [Test] // adapted from bug #78777
- public void MeasureCharacterRanges_TwoLines ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "this\nis a test";
- CharacterRange[] ranges = new CharacterRange[2];
- ranges[0] = new CharacterRange (0, 5);
- ranges[1] = new CharacterRange (5, 9);
- StringFormat string_format = new StringFormat ();
- string_format.FormatFlags = StringFormatFlags.NoClip;
- string_format.SetMeasurableCharacterRanges (ranges);
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
- RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
- Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
- Assert.AreEqual (2, regions.Length, "Length");
- Assert.AreEqual (regions[0].GetBounds (g).Height, regions[1].GetBounds (g).Height, "Height");
- }
- }
- }
- private void MeasureCharacterRanges (string text, int first, int length)
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- CharacterRange[] ranges = new CharacterRange[1];
- ranges[0] = new CharacterRange (first, length);
- StringFormat string_format = new StringFormat ();
- string_format.FormatFlags = StringFormatFlags.NoClip;
- string_format.SetMeasurableCharacterRanges (ranges);
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
- RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
- g.MeasureCharacterRanges (text, font, layout_rect, string_format);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void MeasureCharacterRanges_FirstTooFar ()
- {
- string text = "this\nis a test";
- MeasureCharacterRanges (text, text.Length, 1);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void MeasureCharacterRanges_LengthTooLong ()
- {
- string text = "this\nis a test";
- MeasureCharacterRanges (text, 0, text.Length + 1);
- }
- [Test]
- public void MeasureCharacterRanges_Prefix ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "Hello &Mono::";
- CharacterRange[] ranges = new CharacterRange[1];
- ranges[0] = new CharacterRange (5, 4);
- StringFormat string_format = new StringFormat ();
- string_format.SetMeasurableCharacterRanges (ranges);
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
- RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
- // here & is part of the measure and visible
- string_format.HotkeyPrefix = HotkeyPrefix.None;
- Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
- RectangleF bounds_none = regions[0].GetBounds (g);
- // here & is part of the measure (range) but visible as an underline
- string_format.HotkeyPrefix = HotkeyPrefix.Show;
- regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
- RectangleF bounds_show = regions[0].GetBounds (g);
- Assert.IsTrue (bounds_show.Width < bounds_none.Width, "Show<None");
- // here & is part of the measure (range) but invisible
- string_format.HotkeyPrefix = HotkeyPrefix.Hide;
- regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
- RectangleF bounds_hide = regions[0].GetBounds (g);
- Assert.AreEqual (bounds_hide.Width, bounds_show.Width, "Hide==None");
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void MeasureCharacterRanges_NullStringFormat ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- g.MeasureCharacterRanges ("Mono", font, new RectangleF (), null);
- }
- }
- }
- [Test]
- [Category ("NotWorking")]
- public void MeasureCharacterRanges_StringFormat_Alignment ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "Hello Mono::";
- CharacterRange[] ranges = new CharacterRange[1];
- ranges[0] = new CharacterRange (5, 4);
- StringFormat string_format = new StringFormat ();
- string_format.SetMeasurableCharacterRanges (ranges);
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- string_format.Alignment = StringAlignment.Near;
- Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Near.Region");
- RectangleF near = regions[0].GetBounds (g);
- string_format.Alignment = StringAlignment.Center;
- regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Center.Region");
- RectangleF center = regions[0].GetBounds (g);
- string_format.Alignment = StringAlignment.Far;
- regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Far.Region");
- RectangleF far = regions[0].GetBounds (g);
- Assert.IsTrue (near.X < center.X, "near-center/X");
- Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
- Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
- Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
- Assert.IsTrue (center.X < far.X, "center-far/X");
- Assert.AreEqual (center.Y, far.Y, "center-far/Y");
- Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
- Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
- }
- }
- }
- [Test]
- [Category ("NotWorking")]
- public void MeasureCharacterRanges_StringFormat_LineAlignment ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "Hello Mono::";
- CharacterRange[] ranges = new CharacterRange[1];
- ranges[0] = new CharacterRange (5, 4);
- StringFormat string_format = new StringFormat ();
- string_format.SetMeasurableCharacterRanges (ranges);
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- string_format.LineAlignment = StringAlignment.Near;
- Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Near.Region");
- RectangleF near = regions[0].GetBounds (g);
- string_format.LineAlignment = StringAlignment.Center;
- regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Center.Region");
- RectangleF center = regions[0].GetBounds (g);
- string_format.LineAlignment = StringAlignment.Far;
- regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Far.Region");
- RectangleF far = regions[0].GetBounds (g);
- Assert.AreEqual (near.X, center.X, 0.1, "near-center/X");
- Assert.IsTrue (near.Y < center.Y, "near-center/Y");
- Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
- Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
- Assert.AreEqual (center.X, far.X, 0.1, "center-far/X");
- Assert.IsTrue (center.Y < far.Y, "center-far/Y");
- Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
- Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
- }
- }
- }
- [Test]
- [Category ("NotWorking")]
- public void MeasureCharacterRanges_StringFormat_Alignment_DirectionVertical ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "Hello Mono::";
- CharacterRange[] ranges = new CharacterRange[1];
- ranges[0] = new CharacterRange (5, 4);
- StringFormat string_format = new StringFormat ();
- string_format.FormatFlags = StringFormatFlags.DirectionVertical;
- string_format.SetMeasurableCharacterRanges (ranges);
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- string_format.Alignment = StringAlignment.Near;
- Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Near.Region");
- RectangleF near = regions[0].GetBounds (g);
- string_format.Alignment = StringAlignment.Center;
- regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Center.Region");
- RectangleF center = regions[0].GetBounds (g);
- string_format.Alignment = StringAlignment.Far;
- regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Far.Region");
- RectangleF far = regions[0].GetBounds (g);
- Assert.IsTrue (near.X == center.X, "near-center/X"); // ???
- Assert.IsTrue (near.Y < center.Y, "near-center/Y");
- Assert.IsTrue (near.Width == center.Width, "near-center/Width"); // ???
- Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
- Assert.AreEqual (center.X, far.X, 0.1, "center-far/X");
- Assert.IsTrue (center.Y < far.Y, "center-far/Y");
- Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
- Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
- }
- }
- }
- [Test]
- [Category ("NotWorking")]
- public void MeasureCharacterRanges_StringFormat_LineAlignment_DirectionVertical ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "Hello Mono::";
- CharacterRange[] ranges = new CharacterRange[1];
- ranges[0] = new CharacterRange (5, 4);
- StringFormat string_format = new StringFormat ();
- string_format.FormatFlags = StringFormatFlags.DirectionVertical;
- string_format.SetMeasurableCharacterRanges (ranges);
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- string_format.LineAlignment = StringAlignment.Near;
- Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Near.Region");
- RectangleF near = regions[0].GetBounds (g);
- string_format.LineAlignment = StringAlignment.Center;
- regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Center.Region");
- RectangleF center = regions[0].GetBounds (g);
- string_format.LineAlignment = StringAlignment.Far;
- regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
- Assert.AreEqual (1, regions.Length, "Far.Region");
- RectangleF far = regions[0].GetBounds (g);
- Assert.IsTrue (near.X < center.X, "near-center/X");
- Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
- Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
- Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
- Assert.IsTrue (center.X < far.X, "center-far/X");
- Assert.AreEqual (center.Y, far.Y, 0.1, "center-far/Y");
- Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
- Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
- }
- }
- }
- static CharacterRange [] ranges = new CharacterRange [] {
- new CharacterRange (0, 1),
- new CharacterRange (1, 1),
- new CharacterRange (2, 1)
- };
- Region [] Measure (Graphics gfx, RectangleF rect)
- {
- using (StringFormat format = StringFormat.GenericTypographic) {
- format.SetMeasurableCharacterRanges (ranges);
- using (Font font = new Font (FontFamily.GenericSerif, 11.0f)) {
- return gfx.MeasureCharacterRanges ("abc", font, rect, format);
- }
- }
- }
- [Test]
- public void Measure ()
- {
- using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
- Region [] zero = Measure (gfx, new RectangleF (0, 0, 0, 0));
- Assert.AreEqual (3, zero.Length, "zero.Length");
- Region [] small = Measure (gfx, new RectangleF (0, 0, 100, 100));
- Assert.AreEqual (3, small.Length, "small.Length");
- for (int i = 0; i < 3; i++ ) {
- RectangleF zb = zero [i].GetBounds (gfx);
- RectangleF sb = small [i].GetBounds (gfx);
- Assert.AreEqual (sb.X, zb.X, "sx" + i.ToString ());
- Assert.AreEqual (sb.Y, zb.Y, "sy" + i.ToString ());
- Assert.AreEqual (sb.Width, zb.Width, "sw" + i.ToString ());
- Assert.AreEqual (sb.Height, zb.Height, "sh" + i.ToString ());
- }
- Region [] max = Measure (gfx, new RectangleF (0, 0, Single.MaxValue, Single.MaxValue));
- Assert.AreEqual (3, max.Length, "empty.Length");
- for (int i = 0; i < 3; i++) {
- RectangleF zb = zero [i].GetBounds (gfx);
- RectangleF mb = max [i].GetBounds (gfx);
- Assert.AreEqual (mb.X, zb.X, "mx" + i.ToString ());
- Assert.AreEqual (mb.Y, zb.Y, "my" + i.ToString ());
- Assert.AreEqual (mb.Width, zb.Width, "mw" + i.ToString ());
- Assert.AreEqual (mb.Height, zb.Height, "mh" + i.ToString ());
- }
- }
- }
- [Test]
- public void MeasureLimits ()
- {
- using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
- Region [] min = Measure (gfx, new RectangleF (0, 0, Single.MinValue, Single.MinValue));
- Assert.AreEqual (3, min.Length, "origin.Length");
- for (int i = 0; i < 3; i++) {
- RectangleF mb = min [i].GetBounds (gfx);
- Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
- Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
- Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
- Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
- }
- Region [] neg = Measure (gfx, new RectangleF (0, 0, -20, -20));
- Assert.AreEqual (3, neg.Length, "neg.Length");
- for (int i = 0; i < 3; i++) {
- RectangleF mb = neg [i].GetBounds (gfx);
- Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
- Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
- Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
- Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
- }
- }
- }
- [Test]
- public void DrawString_EndlessLoop_Bug77699 ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- Rectangle rect = Rectangle.Empty;
- rect.Location = new Point (10, 10);
- rect.Size = new Size (1, 20);
- StringFormat fmt = new StringFormat ();
- fmt.Alignment = StringAlignment.Center;
- fmt.LineAlignment = StringAlignment.Center;
- fmt.FormatFlags = StringFormatFlags.NoWrap;
- fmt.Trimming = StringTrimming.EllipsisWord;
- g.DrawString ("Test String", font, Brushes.Black, rect, fmt);
- }
- }
- }
- [Test]
- public void DrawString_EndlessLoop_Wrapping ()
- {
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- Rectangle rect = Rectangle.Empty;
- rect.Location = new Point (10, 10);
- rect.Size = new Size (1, 20);
- StringFormat fmt = new StringFormat ();
- fmt.Alignment = StringAlignment.Center;
- fmt.LineAlignment = StringAlignment.Center;
- fmt.Trimming = StringTrimming.EllipsisWord;
- g.DrawString ("Test String", font, Brushes.Black, rect, fmt);
- }
- }
- }
- [Test]
- public void MeasureString_Wrapping_Dots ()
- {
- HostIgnoreList.CheckTest ("MonoTests.System.Drawing.GraphicsTest.MeasureString_Wrapping_Dots");
- if (font == null)
- Assert.Ignore ("Couldn't create required font");
- string text = "this is really long text........................................... with a lot o periods.";
- using (Bitmap bitmap = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bitmap)) {
- using (StringFormat format = new StringFormat ()) {
- format.Alignment = StringAlignment.Center;
- SizeF sz = g.MeasureString (text, font, 80, format);
- Assert.IsTrue (sz.Width < 80, "Width");
- Assert.IsTrue (sz.Height > font.Height * 2, "Height");
- }
- }
- }
- }
- [Test]
- public void GetReleaseHdcInternal ()
- {
- using (Bitmap b = new Bitmap (10, 10)) {
- using (Graphics g = Graphics.FromImage (b)) {
- IntPtr hdc1 = g.GetHdc ();
- g.ReleaseHdcInternal (hdc1);
- IntPtr hdc2 = g.GetHdc ();
- g.ReleaseHdcInternal (hdc2);
- Assert.AreEqual (hdc1, hdc2, "hdc");
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void ReleaseHdcInternal_IntPtrZero ()
- {
- using (Bitmap b = new Bitmap (10, 10)) {
- using (Graphics g = Graphics.FromImage (b)) {
- g.ReleaseHdcInternal (IntPtr.Zero);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void ReleaseHdcInternal_TwoTimes ()
- {
- using (Bitmap b = new Bitmap (10, 10)) {
- using (Graphics g = Graphics.FromImage (b)) {
- IntPtr hdc = g.GetHdc ();
- g.ReleaseHdcInternal (hdc);
- g.ReleaseHdcInternal (hdc);
- }
- }
- }
- #if NET_2_0
- [Test]
- public void TestReleaseHdc ()
- {
- using (Bitmap b = new Bitmap (10, 10)) {
- using (Graphics g = Graphics.FromImage (b)) {
- IntPtr hdc1 = g.GetHdc ();
- g.ReleaseHdc ();
- IntPtr hdc2 = g.GetHdc ();
- g.ReleaseHdc ();
- Assert.AreEqual (hdc1, hdc2, "hdc");
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void TestReleaseHdcException ()
- {
- using (Bitmap b = new Bitmap (10, 10)) {
- using (Graphics g = Graphics.FromImage (b)) {
- g.ReleaseHdc ();
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void TestReleaseHdcException2 ()
- {
- using (Bitmap b = new Bitmap (10, 10)) {
- using (Graphics g = Graphics.FromImage (b)) {
- g.GetHdc ();
- g.ReleaseHdc ();
- g.ReleaseHdc ();
- }
- }
- }
- #endif
- [Test]
- public void VisibleClipBound ()
- {
- // see #78958
- using (Bitmap bmp = new Bitmap (100, 100)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- RectangleF noclip = g.VisibleClipBounds;
- Assert.AreEqual (0, noclip.X, "noclip.X");
- Assert.AreEqual (0, noclip.Y, "noclip.Y");
- Assert.AreEqual (100, noclip.Width, "noclip.Width");
- Assert.AreEqual (100, noclip.Height, "noclip.Height");
- // note: libgdiplus regions are precise to multiple of multiple of 8
- g.Clip = new Region (new RectangleF (0, 0, 32, 32));
- RectangleF clip = g.VisibleClipBounds;
- Assert.AreEqual (0, clip.X, "clip.X");
- Assert.AreEqual (0, clip.Y, "clip.Y");
- Assert.AreEqual (32, clip.Width, "clip.Width");
- Assert.AreEqual (32, clip.Height, "clip.Height");
- g.RotateTransform (90);
- RectangleF rotclip = g.VisibleClipBounds;
- Assert.AreEqual (0, rotclip.X, "rotclip.X");
- Assert.AreEqual (-32, rotclip.Y, "rotclip.Y");
- Assert.AreEqual (32, rotclip.Width, "rotclip.Width");
- Assert.AreEqual (32, rotclip.Height, "rotclip.Height");
- }
- }
- }
- [Test]
- public void VisibleClipBound_BigClip ()
- {
- using (Bitmap bmp = new Bitmap (100, 100)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- RectangleF noclip = g.VisibleClipBounds;
- Assert.AreEqual (0, noclip.X, "noclip.X");
- Assert.AreEqual (0, noclip.Y, "noclip.Y");
- Assert.AreEqual (100, noclip.Width, "noclip.Width");
- Assert.AreEqual (100, noclip.Height, "noclip.Height");
- // clip is larger than bitmap
- g.Clip = new Region (new RectangleF (0, 0, 200, 200));
- RectangleF clipbound = g.ClipBounds;
- Assert.AreEqual (0, clipbound.X, "clipbound.X");
- Assert.AreEqual (0, clipbound.Y, "clipbound.Y");
- Assert.AreEqual (200, clipbound.Width, "clipbound.Width");
- Assert.AreEqual (200, clipbound.Height, "clipbound.Height");
- RectangleF clip = g.VisibleClipBounds;
- Assert.AreEqual (0, clip.X, "clip.X");
- Assert.AreEqual (0, clip.Y, "clip.Y");
- Assert.AreEqual (100, clip.Width, "clip.Width");
- Assert.AreEqual (100, clip.Height, "clip.Height");
- g.RotateTransform (90);
- RectangleF rotclipbound = g.ClipBounds;
- Assert.AreEqual (0, rotclipbound.X, "rotclipbound.X");
- Assert.AreEqual (-200, rotclipbound.Y, "rotclipbound.Y");
- Assert.AreEqual (200, rotclipbound.Width, "rotclipbound.Width");
- Assert.AreEqual (200, rotclipbound.Height, "rotclipbound.Height");
- RectangleF rotclip = g.VisibleClipBounds;
- Assert.AreEqual (0, rotclip.X, "rotclip.X");
- Assert.AreEqual (-100, rotclip.Y, "rotclip.Y");
- Assert.AreEqual (100, rotclip.Width, "rotclip.Width");
- Assert.AreEqual (100, rotclip.Height, "rotclip.Height");
- }
- }
- }
- [Test]
- public void Rotate ()
- {
- using (Bitmap bmp = new Bitmap (100, 50)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- RectangleF vcb = g.VisibleClipBounds;
- Assert.AreEqual (0, vcb.X, "vcb.X");
- Assert.AreEqual (0, vcb.Y, "vcb.Y");
- Assert.AreEqual (100, vcb.Width, "vcb.Width");
- Assert.AreEqual (50, vcb.Height, "vcb.Height");
- g.RotateTransform (90);
- RectangleF rvcb = g.VisibleClipBounds;
- Assert.AreEqual (0, rvcb.X, "rvcb.X");
- Assert.AreEqual (-100, rvcb.Y, "rvcb.Y");
- Assert.AreEqual (50.0f, rvcb.Width, 0.0001, "rvcb.Width");
- Assert.AreEqual (100, rvcb.Height, "rvcb.Height");
- }
- }
- }
- [Test]
- public void Scale ()
- {
- using (Bitmap bmp = new Bitmap (100, 50)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- RectangleF vcb = g.VisibleClipBounds;
- Assert.AreEqual (0, vcb.X, "vcb.X");
- Assert.AreEqual (0, vcb.Y, "vcb.Y");
- Assert.AreEqual (100, vcb.Width, "vcb.Width");
- Assert.AreEqual (50, vcb.Height, "vcb.Height");
- g.ScaleTransform (2, 0.5f);
- RectangleF svcb = g.VisibleClipBounds;
- Assert.AreEqual (0, svcb.X, "svcb.X");
- Assert.AreEqual (0, svcb.Y, "svcb.Y");
- Assert.AreEqual (50, svcb.Width, "svcb.Width");
- Assert.AreEqual (100, svcb.Height, "svcb.Height");
- }
- }
- }
- [Test]
- public void Translate ()
- {
- using (Bitmap bmp = new Bitmap (100, 50)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- RectangleF vcb = g.VisibleClipBounds;
- Assert.AreEqual (0, vcb.X, "vcb.X");
- Assert.AreEqual (0, vcb.Y, "vcb.Y");
- Assert.AreEqual (100, vcb.Width, "vcb.Width");
- Assert.AreEqual (50, vcb.Height, "vcb.Height");
- g.TranslateTransform (-25, 25);
- RectangleF tvcb = g.VisibleClipBounds;
- Assert.AreEqual (25, tvcb.X, "tvcb.X");
- Assert.AreEqual (-25, tvcb.Y, "tvcb.Y");
- Assert.AreEqual (100, tvcb.Width, "tvcb.Width");
- Assert.AreEqual (50, tvcb.Height, "tvcb.Height");
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawIcon_NullRectangle ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawIcon (null, new Rectangle (0, 0, 32, 32));
- }
- }
- }
- [Test]
- public void DrawIcon_IconRectangle ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawIcon (SystemIcons.Application, new Rectangle (0, 0, 40, 20));
- // Rectangle is empty when X, Y, Width and Height == 0
- // (yep X and Y too, RectangleF only checks for Width and Height)
- g.DrawIcon (SystemIcons.Asterisk, new Rectangle (0, 0, 0, 0));
- // so this one is half-empty ;-)
- g.DrawIcon (SystemIcons.Error, new Rectangle (20, 40, 0, 0));
- // negative width or height isn't empty (for Rectangle)
- g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
- g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawIcon_NullIntInt ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawIcon (null, 4, 2);
- }
- }
- }
- [Test]
- public void DrawIcon_IconIntInt ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawIcon (SystemIcons.Exclamation, 4, 2);
- g.DrawIcon (SystemIcons.Hand, 0, 0);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawIconUnstretched_NullRectangle ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawIconUnstretched (null, new Rectangle (0, 0, 40, 20));
- }
- }
- }
- [Test]
- public void DrawIconUnstretched_IconRectangle ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawIconUnstretched (SystemIcons.Information, new Rectangle (0, 0, 40, 20));
- // Rectangle is empty when X, Y, Width and Height == 0
- // (yep X and Y too, RectangleF only checks for Width and Height)
- g.DrawIconUnstretched (SystemIcons.Question, new Rectangle (0, 0, 0, 0));
- // so this one is half-empty ;-)
- g.DrawIconUnstretched (SystemIcons.Warning, new Rectangle (20, 40, 0, 0));
- // negative width or height isn't empty (for Rectangle)
- g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
- g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullRectangleF ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, new RectangleF (0, 0, 0, 0));
- }
- }
- }
- [Test]
- public void DrawImage_ImageRectangleF ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, new RectangleF (0, 0, 0, 0));
- g.DrawImage (bmp, new RectangleF (20, 40, 0, 0));
- g.DrawImage (bmp, new RectangleF (10, 20, -1, 0));
- g.DrawImage (bmp, new RectangleF (20, 10, 0, -1));
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullPointF ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, new PointF (0, 0));
- }
- }
- }
- [Test]
- public void DrawImage_ImagePointF ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, new PointF (0, 0));
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullPointFArray ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, new PointF[0]);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_ImagePointFArrayNull ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, (PointF[]) null);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawImage_ImagePointFArrayEmpty ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, new PointF[0]);
- }
- }
- }
- [Test]
- public void DrawImage_ImagePointFArray ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, new PointF[] {
- new PointF (0, 0), new PointF (1, 1), new PointF (2, 2) });
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullRectangle ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, new Rectangle (0, 0, 0, 0));
- }
- }
- }
- [Test]
- public void DrawImage_ImageRectangle ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- // Rectangle is empty when X, Y, Width and Height == 0
- // (yep X and Y too, RectangleF only checks for Width and Height)
- g.DrawImage (bmp, new Rectangle (0, 0, 0, 0));
- // so this one is half-empty ;-)
- g.DrawImage (bmp, new Rectangle (20, 40, 0, 0));
- // negative width or height isn't empty (for Rectangle)
- g.DrawImage (bmp, new Rectangle (10, 20, -1, 0));
- g.DrawImage (bmp, new Rectangle (20, 10, 0, -1));
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullPoint ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, new Point (0, 0));
- }
- }
- }
- [Test]
- public void DrawImage_ImagePoint ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, new Point (0, 0));
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullPointArray ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, new Point[0]);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_ImagePointArrayNull ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, (Point[]) null);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawImage_ImagePointArrayEmpty ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, new Point[0]);
- }
- }
- }
- [Test]
- public void DrawImage_ImagePointArray ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, new Point[] {
- new Point (0, 0), new Point (1, 1), new Point (2, 2) });
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullIntInt ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, Int32.MaxValue, Int32.MinValue);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (OverflowException))]
- public void DrawImage_ImageIntInt_Overflow ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, Int32.MaxValue, Int32.MinValue);
- }
- }
- }
- [Test]
- public void DrawImage_ImageIntInt ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, -40, -40);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullFloat ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, Single.MaxValue, Single.MinValue);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (OverflowException))]
- public void DrawImage_ImageFloatFloat_Overflow ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, Single.MaxValue, Single.MinValue);
- }
- }
- }
- [Test]
- public void DrawImage_ImageFloatFloat ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, -40.0f, -40.0f);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullRectangleRectangleGraphicsUnit ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, new Rectangle (), new Rectangle (), GraphicsUnit.Display);
- }
- }
- }
- private void DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit unit)
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- Rectangle r = new Rectangle (0, 0, 40, 40);
- g.DrawImage (bmp, r, r, unit);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawImage_ImageRectangleRectangleGraphicsUnit_Display ()
- {
- DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Display);
- }
- [Test]
- [ExpectedException (typeof (NotImplementedException))]
- public void DrawImage_ImageRectangleRectangleGraphicsUnit_Document ()
- {
- DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Document);
- }
- [Test]
- [ExpectedException (typeof (NotImplementedException))]
- public void DrawImage_ImageRectangleRectangleGraphicsUnit_Inch ()
- {
- DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Inch);
- }
- [Test]
- [ExpectedException (typeof (NotImplementedException))]
- public void DrawImage_ImageRectangleRectangleGraphicsUnit_Millimeter ()
- {
- DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Millimeter);
- }
- [Test]
- public void DrawImage_ImageRectangleRectangleGraphicsUnit_Pixel ()
- {
- // this unit works
- DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Pixel);
- }
- [Test]
- [ExpectedException (typeof (NotImplementedException))]
- public void DrawImage_ImageRectangleRectangleGraphicsUnit_Point ()
- {
- DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Point);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawImage_ImageRectangleRectangleGraphicsUnit_World ()
- {
- DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.World);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullPointRectangleGraphicsUnit ()
- {
- Rectangle r = new Rectangle (1, 2, 3, 4);
- Point[] pts = new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) };
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, pts, r, GraphicsUnit.Pixel);
- }
- }
- }
- private void DrawImage_ImagePointRectangleGraphicsUnit (Point[] pts)
- {
- Rectangle r = new Rectangle (1, 2, 3, 4);
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_ImageNullRectangleGraphicsUnit ()
- {
- DrawImage_ImagePointRectangleGraphicsUnit (null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawImage_ImagePoint0RectangleGraphicsUnit ()
- {
- DrawImage_ImagePointRectangleGraphicsUnit (new Point[0]);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawImage_ImagePoint1RectangleGraphicsUnit ()
- {
- Point p = new Point (1, 1);
- DrawImage_ImagePointRectangleGraphicsUnit (new Point[1] { p });
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawImage_ImagePoint2RectangleGraphicsUnit ()
- {
- Point p = new Point (1, 1);
- DrawImage_ImagePointRectangleGraphicsUnit (new Point[2] { p, p });
- }
- [Test]
- public void DrawImage_ImagePoint3RectangleGraphicsUnit ()
- {
- Point p = new Point (1, 1);
- DrawImage_ImagePointRectangleGraphicsUnit (new Point[3] { p, p, p });
- }
- [Test]
- [ExpectedException (typeof (NotImplementedException))]
- public void DrawImage_ImagePoint4RectangleGraphicsUnit ()
- {
- Point p = new Point (1, 1);
- DrawImage_ImagePointRectangleGraphicsUnit (new Point[4] { p, p, p, p });
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_NullPointFRectangleGraphicsUnit ()
- {
- Rectangle r = new Rectangle (1, 2, 3, 4);
- PointF[] pts = new PointF[3] { new PointF (1, 1), new PointF (2, 2), new PointF (3, 3) };
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (null, pts, r, GraphicsUnit.Pixel);
- }
- }
- }
- private void DrawImage_ImagePointFRectangleGraphicsUnit (PointF[] pts)
- {
- Rectangle r = new Rectangle (1, 2, 3, 4);
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImage_ImageNullFRectangleGraphicsUnit ()
- {
- DrawImage_ImagePointFRectangleGraphicsUnit (null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawImage_ImagePointF0RectangleGraphicsUnit ()
- {
- DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[0]);
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawImage_ImagePointF1RectangleGraphicsUnit ()
- {
- PointF p = new PointF (1, 1);
- DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[1] { p });
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void DrawImage_ImagePointF2RectangleGraphicsUnit ()
- {
- PointF p = new PointF (1, 1);
- DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[2] { p, p });
- }
- [Test]
- public void DrawImage_ImagePointF3RectangleGraphicsUnit ()
- {
- PointF p = new PointF (1, 1);
- DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[3] { p, p, p });
- }
- [Test]
- [ExpectedException (typeof (NotImplementedException))]
- public void DrawImage_ImagePointF4RectangleGraphicsUnit ()
- {
- PointF p = new PointF (1, 1);
- DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[4] { p, p, p, p });
- }
- [Test]
- public void DrawImage_ImagePointRectangleGraphicsUnitNull ()
- {
- Point p = new Point (1, 1);
- Point[] pts = new Point[3] { p, p, p };
- Rectangle r = new Rectangle (1, 2, 3, 4);
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel, null);
- }
- }
- }
- [Test]
- public void DrawImage_ImagePointRectangleGraphicsUnitAttributes ()
- {
- Point p = new Point (1, 1);
- Point[] pts = new Point[3] { p, p, p };
- Rectangle r = new Rectangle (1, 2, 3, 4);
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- ImageAttributes ia = new ImageAttributes ();
- g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel, ia);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImageUnscaled_NullPoint ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImageUnscaled (null, new Point (0, 0));
- }
- }
- }
- [Test]
- public void DrawImageUnscaled_ImagePoint ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImageUnscaled (bmp, new Point (0, 0));
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImageUnscaled_NullRectangle ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImageUnscaled (null, new Rectangle (0, 0, -1, -1));
- }
- }
- }
- [Test]
- public void DrawImageUnscaled_ImageRectangle ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImageUnscaled (bmp, new Rectangle (0, 0, -1, -1));
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImageUnscaled_NullIntInt ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImageUnscaled (null, 0, 0);
- }
- }
- }
- [Test]
- public void DrawImageUnscaled_ImageIntInt ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImageUnscaled (bmp, 0, 0);
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImageUnscaled_NullIntIntIntInt ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImageUnscaled (null, 0, 0, -1, -1);
- }
- }
- }
- [Test]
- public void DrawImageUnscaled_ImageIntIntIntInt ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImageUnscaled (bmp, 0, 0, -1, -1);
- }
- }
- }
- #if NET_2_0
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawImageUnscaledAndClipped_Null ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawImageUnscaledAndClipped (null, new Rectangle (0, 0, 0, 0));
- }
- }
- }
- [Test]
- public void DrawImageUnscaledAndClipped ()
- {
- using (Bitmap bmp = new Bitmap (40, 40)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- // Rectangle is empty when X, Y, Width and Height == 0
- // (yep X and Y too, RectangleF only checks for Width and Height)
- g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 0, 0));
- // so this one is half-empty ;-)
- g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 40, 0, 0));
- // negative width or height isn't empty (for Rectangle)
- g.DrawImageUnscaledAndClipped (bmp, new Rectangle (10, 20, -1, 0));
- g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 10, 0, -1));
- // smaller
- g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 10, 20));
- g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 40, 10));
- g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 80, 20));
- }
- }
- }
- #endif
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawPath_Pen_Null ()
- {
- using (Bitmap bmp = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- using (GraphicsPath path = new GraphicsPath ()) {
- g.DrawPath (null, path);
- }
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void DrawPath_Path_Null ()
- {
- using (Bitmap bmp = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.DrawPath (Pens.Black, null);
- }
- }
- }
- [Test]
- public void DrawPath_82202 ()
- {
- // based on test case from bug #82202
- using (Bitmap bmp = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- using (GraphicsPath path = new GraphicsPath ()) {
- int d = 5;
- Rectangle baserect = new Rectangle (0, 0, 19, 19);
- Rectangle arcrect = new Rectangle (baserect.Location, new Size (d, d));
- path.AddArc (arcrect, 180, 90);
- arcrect.X = baserect.Right - d;
- path.AddArc (arcrect, 270, 90);
- arcrect.Y = baserect.Bottom - d;
- path.AddArc (arcrect, 0, 90);
- arcrect.X = baserect.Left;
- path.AddArc (arcrect, 90, 90);
- path.CloseFigure ();
- g.Clear (Color.White);
- g.DrawPath (Pens.SteelBlue, path);
- Assert.AreEqual (-12156236, bmp.GetPixel (0, 9).ToArgb (), "0,9");
- Assert.AreEqual (-1, bmp.GetPixel (1, 9).ToArgb (), "1,9");
- }
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void FillPath_Brush_Null ()
- {
- using (Bitmap bmp = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- using (GraphicsPath path = new GraphicsPath ()) {
- g.FillPath (null, path);
- }
- }
- }
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void FillPath_Path_Null ()
- {
- using (Bitmap bmp = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- g.FillPath (Brushes.Black, null);
- }
- }
- }
- [Test]
- public void FillPath_82202 ()
- {
- // based on test case from bug #82202
- using (Bitmap bmp = new Bitmap (20, 20)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- using (GraphicsPath path = new GraphicsPath ()) {
- int d = 5;
- Rectangle baserect = new Rectangle (0, 0, 19, 19);
- Rectangle arcrect = new Rectangle (baserect.Location, new Size (d, d));
- path.AddArc (arcrect, 180, 90);
- arcrect.X = baserect.Right - d;
- path.AddArc (arcrect, 270, 90);
- arcrect.Y = baserect.Bottom - d;
- path.AddArc (arcrect, 0, 90);
- arcrect.X = baserect.Left;
- path.AddArc (arcrect, 90, 90);
- path.CloseFigure ();
- g.Clear (Color.White);
- g.FillPath (Brushes.SteelBlue, path);
- Assert.AreEqual (-12156236, bmp.GetPixel (0, 9).ToArgb (), "0,9");
- Assert.AreEqual (-12156236, bmp.GetPixel (1, 9).ToArgb (), "1,9");
- }
- }
- }
- }
- [Test]
- public void TransformPoints_349800 ()
- {
- using (Bitmap bmp = new Bitmap (10, 10)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- Point [] pts = new Point [5];
- PointF [] ptf = new PointF [5];
- for (int i = 0; i < 5; i++) {
- pts [i] = new Point (i, i);
- ptf [i] = new PointF (i, i);
- }
- g.TransformPoints (CoordinateSpace.Page, CoordinateSpace.Device, pts);
- g.TransformPoints (CoordinateSpace.Page, CoordinateSpace.Device, ptf);
- for (int i = 0; i < 5; i++) {
- Assert.AreEqual (i, pts [i].X, "Point.X " + i.ToString ());
- Assert.AreEqual (i, pts [i].Y, "Point.Y " + i.ToString ());
- Assert.AreEqual (i, ptf [i].X, "PointF.X " + i.ToString ());
- Assert.AreEqual (i, ptf [i].Y, "PointF.Y " + i.ToString ());
- }
- }
- }
- }
- [Test]
- public void Dpi_556181 ()
- {
- float x, y;
- using (Bitmap bmp = new Bitmap (10, 10)) {
- using (Graphics g = Graphics.FromImage (bmp)) {
- x = g.DpiX - 10;
- y = g.DpiY + 10;
- }
- bmp.SetResolution (x, y);
- using (Graphics g = Graphics.FromImage (bmp)) {
- Assert.AreEqual (x, g.DpiX, "DpiX");
- Assert.AreEqual (y, g.DpiY, "DpiY");
- }
- }
- }
- }
- [TestFixture]
- public class GraphicsFullTrustTest {
- // note: this test would fail, on ReleaseHdc, without fulltrust
- // i.e. it's a demand and not a linkdemand
- [Test]
- public void GetReleaseHdc ()
- {
- using (Bitmap b = new Bitmap (100, 100)) {
- using (Graphics g = Graphics.FromImage (b)) {
- IntPtr hdc1 = g.GetHdc ();
- g.ReleaseHdc (hdc1);
- IntPtr hdc2 = g.GetHdc ();
- g.ReleaseHdc (hdc2);
- Assert.AreEqual (hdc1, hdc2, "hdc");
- }
- }
- }
- }
- }
|