00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "nsCOMPtr.h"
00040 #include "nsISVGLibartRegion.h"
00041 #include "nsSVGLibartRegion.h"
00042 #include "nsISVGRectangleSink.h"
00043 #include <math.h>
00044
00049
00050
00053 class nsSVGLibartRegion : public nsISVGLibartRegion
00054 {
00055 protected:
00056 friend nsresult NS_NewSVGLibartRectRegion(nsISVGRendererRegion** result,
00057 float x, float y,
00058 float width, float height);
00059 friend nsresult NS_NewSVGLibartSVPRegion(nsISVGRendererRegion** result,
00060 ArtSVP *path);
00061 nsSVGLibartRegion(ArtIRect *rect);
00062 nsSVGLibartRegion(ArtSVP* path);
00063 nsSVGLibartRegion(ArtUta* uta);
00064
00065 ~nsSVGLibartRegion();
00066
00067 public:
00068
00069 NS_DECL_ISUPPORTS
00070
00071
00072 NS_IMETHOD_(ArtUta*) GetUta();
00073
00074
00075 NS_DECL_NSISVGRENDERERREGION
00076
00077 private:
00078 ArtUta* mUta;
00079 };
00080
00083
00084
00085
00086 nsSVGLibartRegion::nsSVGLibartRegion(ArtIRect *rect)
00087 {
00088 mUta = art_uta_from_irect(rect);
00089 }
00090
00091 nsSVGLibartRegion::nsSVGLibartRegion(ArtSVP* path)
00092 {
00093 mUta = path ? art_uta_from_svp(path) : nsnull;
00094 }
00095
00096 nsSVGLibartRegion::nsSVGLibartRegion(ArtUta* uta)
00097 : mUta(uta)
00098 {
00099 }
00100
00101 nsSVGLibartRegion::~nsSVGLibartRegion()
00102 {
00103 if (mUta)
00104 art_uta_free(mUta);
00105 }
00106
00107 nsresult
00108 NS_NewSVGLibartRectRegion(nsISVGRendererRegion** result,
00109 float x, float y,
00110 float width, float height)
00111 {
00112 if (width<=0.0f || height<=0.0f) {
00113 *result = new nsSVGLibartRegion((ArtUta*)nsnull);
00114 }
00115 else {
00116 ArtIRect irect;
00117 irect.x0 = (int)x;
00118 irect.y0 = (int)y;
00119 irect.x1 = (int)ceil(x+width);
00120 irect.y1 = (int)ceil(y+height);
00121 NS_ASSERTION(irect.x0!=irect.x1 && irect.y0!=irect.y1, "empty region");
00122 *result = new nsSVGLibartRegion(&irect);
00123 }
00124
00125 if (!*result) return NS_ERROR_OUT_OF_MEMORY;
00126
00127 NS_ADDREF(*result);
00128 return NS_OK;
00129 }
00130
00131 nsresult
00132 NS_NewSVGLibartSVPRegion(nsISVGRendererRegion** result,
00133 ArtSVP* path)
00134 {
00135 *result = new nsSVGLibartRegion(path);
00136 if (!*result) return NS_ERROR_OUT_OF_MEMORY;
00137
00138 NS_ADDREF(*result);
00139 return NS_OK;
00140 }
00141
00142
00143
00144
00145
00146 NS_IMPL_ADDREF(nsSVGLibartRegion)
00147 NS_IMPL_RELEASE(nsSVGLibartRegion)
00148
00149 NS_INTERFACE_MAP_BEGIN(nsSVGLibartRegion)
00150 NS_INTERFACE_MAP_ENTRY(nsISVGLibartRegion)
00151 NS_INTERFACE_MAP_ENTRY(nsISVGRendererRegion)
00152 NS_INTERFACE_MAP_ENTRY(nsISupports)
00153 NS_INTERFACE_MAP_END
00154
00155
00156
00157
00158 NS_IMETHODIMP_(ArtUta*)
00159 nsSVGLibartRegion::GetUta()
00160 {
00161 return mUta;
00162 }
00163
00164
00165
00166
00168 NS_IMETHODIMP
00169 nsSVGLibartRegion::Combine(nsISVGRendererRegion *other,
00170 nsISVGRendererRegion **_retval)
00171 {
00172 *_retval = nsnull;
00173
00174 nsCOMPtr<nsISVGLibartRegion> other2 = do_QueryInterface(other);
00175 if (!other2) {
00176 NS_WARNING("Union operation on incompatible regions");
00177 return NS_ERROR_FAILURE;
00178 }
00179
00180 nsISVGLibartRegion *regions[2];
00181 int count = 0;
00182
00183 if (mUta)
00184 regions[count++]=this;
00185
00186 if (other2->GetUta())
00187 regions[count++]=other2;
00188
00189 switch (count) {
00190 case 0:
00191 break;
00192 case 1:
00193 *_retval = regions[0];
00194 NS_ADDREF(*_retval);
00195 break;
00196 case 2:
00197 *_retval = new nsSVGLibartRegion(art_uta_union(regions[0]->GetUta(),
00198 regions[1]->GetUta()));
00199 NS_IF_ADDREF(*_retval);
00200 break;
00201 }
00202
00203 return NS_OK;
00204 }
00205
00207 NS_IMETHODIMP
00208 nsSVGLibartRegion::GetRectangleScans(nsISVGRectangleSink *sink)
00209 {
00210 if (!mUta) return NS_OK;
00211
00212 int nRects=0;
00213 ArtIRect* rectList = art_rect_list_from_uta(mUta, 200, 200, &nRects);
00214 for (int i=0; i<nRects; ++i) {
00215 int x,y,w,h;
00216 x = PR_MIN(rectList[i].x0,rectList[i].x1)-2;
00217 y = PR_MIN(rectList[i].y0,rectList[i].y1)-2;
00218 w = PR_ABS(rectList[i].x0-rectList[i].x1)+4;
00219 h = PR_ABS(rectList[i].y0-rectList[i].y1)+4;
00220
00221 sink->SinkRectangle(x,y,w,h);
00222 }
00223
00224 art_free(rectList);
00225
00226 return NS_OK;
00227 }