예제 #1
0
        public IEnumerable<Overlay> GetOverlays(string virtualPath, System.Collections.Specialized.NameValueCollection query)
        {
            string poly = query["customoverlay.coords"];
            string align = query["customoverlay.align"];
            string image = query["customoverlay.image"];
            string w = query["customoverlay.magicwidth"];
            string h = query["customoverlay.magicheight"];
            if (string.IsNullOrEmpty(poly) || string.IsNullOrEmpty(image)) return null; //Don't process this image, it's not ours

            string[] coords = poly.Split(',');

            if (coords.Length != 8 && coords.Length != 4) return null; //Not valid coords

            Overlay o = new Overlay();
            //Parse points
            o.Poly = new PointF[4];
            for (int i = 0; i < 4; i++) {
                if (coords.Length == 8) {
                    o.Poly[i] = new PointF(float.Parse(coords[i * 2]), float.Parse(coords[i * 2 + 1]));
                } else {
                    o.Poly[i] = new PointF(float.Parse(coords[(i == 3 || i == 0) ? 0 : 2]), float.Parse(coords[(i == 0 || i == 1) ? 1 : 3]));
                }
            }
            //Parse alignment
            o.Align = string.IsNullOrEmpty(align) ?  ContentAlignment.MiddleCenter : (ContentAlignment)Enum.Parse(typeof(ContentAlignment), align,true);

            //Parse magic sizes
            if (!string.IsNullOrEmpty(w)) o.PolyWidthInLogoPixels = float.Parse(w);
            if (!string.IsNullOrEmpty(h)) o.PolyHeightInLogoPixels = float.Parse(h);

            //Build path
            o.OverlayPath = OverlayFolder.TrimEnd('/') + '/' + Util.PathUtils.RemoveNonMatchingChars(image, ValidImageChars);

            return new Overlay[] { o };
        }
예제 #2
0
        public PointF[] GetOverlayParalellogram(Overlay o, Size nativeSize, ImageState translateToFinalCoordinateSpace)
        {
            //What's the polygon w/h?
            double cw = PolygonMath.Dist(o.Poly[0], o.Poly[1]);
            double ch = PolygonMath.Dist(o.Poly[1], o.Poly[2]);
            //Take a copy to shrink to content size
            double w = cw;
            double h = ch;

            double aspect = (double)nativeSize.Height / (double)nativeSize.Width;

            //If specified, what percentage of the space do we use?
            if (o.PolyWidthInLogoPixels > 0) {
                w = cw * (double)nativeSize.Width / o.PolyWidthInLogoPixels;
                if (o.RespectOnlyMatchingBound) h = w * aspect;
            }

            if (o.PolyHeightInLogoPixels > 0) {
                h = ch * (double)nativeSize.Height / o.PolyHeightInLogoPixels;
                if (o.RespectOnlyMatchingBound && o.PolyWidthInLogoPixels <= 0) w = h / aspect;
            }

            //Shrink to keep aspect ratio
            if (w / h > 1 / aspect) {
                w = h / aspect;
            } else {
                h = w * aspect;
            }
            //Let's define our width/height offsets
            double ox = 0; double oy = 0; ;

            //Apply alignment to ox, oy
            if (o.Align == ContentAlignment.BottomLeft || o.Align == ContentAlignment.MiddleLeft || o.Align == ContentAlignment.TopLeft)
                ox = 0;
            if (o.Align == ContentAlignment.BottomCenter || o.Align == ContentAlignment.MiddleCenter || o.Align == ContentAlignment.TopCenter)
                ox = (cw - w) / 2;
            if (o.Align == ContentAlignment.BottomRight || o.Align == ContentAlignment.MiddleRight || o.Align == ContentAlignment.TopRight)
                ox = cw - w;
            if (o.Align == ContentAlignment.TopLeft || o.Align == ContentAlignment.TopCenter || o.Align == ContentAlignment.TopRight)
                oy = 0;
            if (o.Align == ContentAlignment.MiddleLeft || o.Align == ContentAlignment.MiddleCenter || o.Align == ContentAlignment.MiddleRight)
                oy = (ch - h) / 2;
            if (o.Align == ContentAlignment.BottomLeft || o.Align == ContentAlignment.BottomCenter || o.Align == ContentAlignment.BottomRight)
                oy = ch - h;

            //Now, we need to rotate everything to match the rotation of the original parallelogram
            double angle = Math.Atan2(o.Poly[1].Y - o.Poly[0].Y, o.Poly[1].X - o.Poly[0].X);

            PointF[] t = new PointF[4];
            t[0] = CreateVector(CreateVector(o.Poly[0], angle, ox), angle + Math.PI / 2, oy);
            t[1] = CreateVector(t[0], angle, w);
            t[2] = CreateVector(t[1], angle + Math.PI / 2, h);
            t[3] = CreateVector(t[0], angle + Math.PI / 2, h);

            //Translate the points if a ImageState instance was specified
            if (translateToFinalCoordinateSpace != null) return this.TranslatePoints(t, translateToFinalCoordinateSpace);
            return t;
        }
        //private Overlay GetOverlayFromDb(int designMapId, int masterId, int colorId) {
        private Overlay GetOverlayFromDb(int designId, int masterId, int colorId, int orgId, int logoUsageId)
        {
            using (var conn = GetConnection()) {
                conn.Open();
                var c = new SqlCommand(SqlQuery, conn);
                c.Parameters.AddWithValue("designid", designId);
                c.Parameters.AddWithValue("masterid", masterId);
                c.Parameters.AddWithValue("colorid", colorId);
                c.Parameters.AddWithValue("orgid", orgId);
                c.Parameters.AddWithValue("logousageid", logoUsageId);

                using (var r = c.ExecuteReader(System.Data.CommandBehavior.SingleRow)) {
                    if (!r.HasRows) return null; //No results?
                    r.Read();

                    /*NickName	Description	IsDarkColor	Description X1	Y1	X2	Y2	X3	Y3	X4	Y4
                    CampusCloz	Alumni 1	1	Full Chest 309	289	705	289	309	384	705	384	*/
                    /*
                    So working through this example which has real values from the NEW sample db I provided:
                    · designid=3233 locates for us LogoDesignMap.ID=3233 which represents a 'Alumni 1' logo design for Org=Campus Cloz in the Full Chest position.
                    · mastid=9464, colorid=1577, and Logo Position=Full Chest are used to locate LogoImage2.ID=63392. Now we know the source product image (1020_99_z.jpg), coordinates for the logo, and the logo position (this answers your question).
                    · colorid=1577 tells us the color is a dark color (Color.IsDarkColor=1). We need to know if color is light or dark because we put white logos on dark colors only, and dark logos on light colors only.
                     * Now we know enough to build the logo filename. This was described in earlier email, but I'll repeat:
                     * Our logo image file names will use a strict naming convention i.e. [Organization.NickName]_[Logo Design Name]_[Light or Dark]_[Logo Position].png,
                     * i.e. CampusCloz_athletics9_light_leftsleeve.png. So, the logo image name should be: CampusCloz_athletics1_dark_FullChest.png. Note we collapse spaces in these file names, i.e. 'Campus Cloz' becomes 'CampusCloz', 'Athletics 1' -> 'Athletics1, 'Full Chest' -> FullChest

                     * */

                    //Build overlay path
                    Overlay o = new Overlay();
                    StringBuilder p = new StringBuilder();
                    //p.AppendFormat("{4}/{0}_{1}_{2}_{3}.png", r.GetString(0), r.GetString(1), r.GetBoolean(2) ? "dark" : "light", r.GetString(3), this.OverlayBasePath.TrimEnd('/'));
                    p.AppendFormat("{4}/{0}/LogoImages/{0}_{1}_{2}_{3}.png", r.GetString(0), r.GetString(1), r.GetBoolean(2) ? "dark" : "light", r.GetString(3), this.OverlayBasePath.TrimEnd('/'));
                    p.Replace(" ", "");
                    o.OverlayPath = p.ToString();

                    //Parse logo position and use it to fill in magic values
                    string logoPosition = r.GetString(3).Replace(" ", "");
                    LogoPosition type = (LogoPosition)Enum.Parse(typeof(LogoPosition), logoPosition, true);
                    this.ApplyLogoPositionMagicValues(o, type);

                    o.Align = (ContentAlignment)r.GetInt32(12);     //LogoAlignment

                    //Store coordinates
                    o.Poly = new PointF[4];
                    for (int i = 0; i < 4; i++) {
                        int x = r.GetInt32(4 + (i * 2));
                        int y = r.GetInt32(5 + (i * 2));
                        o.Poly[i] = new PointF(x, y);
                    }

                    return o;
                }
            }
        }
 /// <summary>
 /// Applies the scaling values based on the logo position
 /// </summary>
 /// <param name="o"></param>
 /// <param name="lp"></param>
 public void ApplyLogoPositionMagicValues(Overlay o, LogoPosition lp)
 {
     //Apply arbitrary pixel scaling factors
     switch (lp) {
         case LogoPosition.CenterChest:
             //6.5" max logo width
             o.PolyWidthInLogoPixels = 218;
             break;
         case LogoPosition.FullChest:
             //12" max logo width
             o.PolyWidthInLogoPixels = 402;
             break;
         case LogoPosition.LeftChest:
             //5.88" max logo width
             o.PolyWidthInLogoPixels = 197;
             break;
         case LogoPosition.LeftThigh:
             //4.5" max logo width
             o.PolyWidthInLogoPixels = 151;
             break;
         case LogoPosition.VerticalLeg:
         case LogoPosition.LeftSleeve:
             //3" max logo width - width of logo is left to right with logo hanging vertically
             //o.PolyWidthInLogoPixels = 101; - In fact, the previous algorithm NEVER applied this value, so specifying it will cause an undesired result.
             o.PolyHeightInLogoPixels = 469; //14" logo
             break;
         case LogoPosition.General:
             //3.5"
             o.PolyWidthInLogoPixels = 118;
             break;
     }
 }
예제 #5
0
        /// <summary>
        /// Returns an enumeration containing a single Overlay instance for the given request.
        /// </summary>
        /// <param name="virtualPath"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public IEnumerable <Overlay> GetOverlays(string virtualPath, NameValueCollection query)
        {
            string sDesign      = query["designid"];
            string sMaster      = query["mastid"];
            string sColor       = query["colorid"];
            string sOrgId       = query["orgid"];
            string sLogoUsageId = query["logousageid"];

            if (string.IsNullOrEmpty(sDesign) || string.IsNullOrEmpty(sMaster) || string.IsNullOrEmpty(sColor) || string.IsNullOrEmpty(sOrgId) || string.IsNullOrEmpty(sLogoUsageId))
            {
                return(null);                                                                                                                                                                      //Don't process this image, it's not ours
            }
            int designId    = 0;
            int masterId    = 0;
            int colorId     = 0;
            int orgId       = 0;
            int logoUsageId = 0;

            if (!int.TryParse(sDesign, out designId) || !(int.TryParse(sMaster, out masterId)) || !int.TryParse(sColor, out colorId) || !int.TryParse(sOrgId, out orgId) || !int.TryParse(sLogoUsageId, out logoUsageId))
            {
                return(null);                                                                                                                                                                                                          //Invalid numbers, fail silently.
            }
            string cacheKey   = sDesign + "_" + sMaster + "_" + sColor + "_" + sOrgId + "_" + sLogoUsageId;
            var    cachedData = HttpRuntime.Cache[cachedDataKey] as Dictionary <string, Overlay>;

            //Load from cache if present
            if (CacheDb && cachedData != null)
            {
                lock (cachedDataSync) {
                    Overlay temp;
                    if (cachedData.TryGetValue(cacheKey, out temp) && (temp != null || CacheNullValues))
                    {
                        return(temp == null ? null :  new Overlay[] { temp });
                    }
                }
            }


            //Cache mis. Let's do our SQL
            Overlay o = GetOverlayFromDb(designId, masterId, colorId, orgId, logoUsageId);

            if (!CacheNullValues && o == null)
            {
                return(null);                               //Item doesn't exist
            }
            if (CacheDb)
            {
                //Save in cache
                lock (cachedDataSync) {
                    //Perform lookup again, don't want to overwrite it
                    var cachedData2 = HttpRuntime.Cache[cachedDataKey] as Dictionary <string, Overlay>;
                    //Ensure the dictionary exists
                    if (cachedData2 == null)
                    {
                        cachedData2 = new Dictionary <string, Overlay>();
                        HttpRuntime.Cache.Add(cachedDataKey, cachedData2, GetDependencies(), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
                    }
                    cachedData2[cacheKey] = o;
                }
            }
            return((o == null) ? null : new Overlay[] { o });
        }
예제 #6
0
        //private Overlay GetOverlayFromDb(int designMapId, int masterId, int colorId) {
        private Overlay GetOverlayFromDb(int designId, int masterId, int colorId, int orgId, int logoUsageId)
        {
            using (var conn = GetConnection()) {
                conn.Open();
                var c = new SqlCommand(SqlQuery, conn);
                c.Parameters.AddWithValue("designid", designId);
                c.Parameters.AddWithValue("masterid", masterId);
                c.Parameters.AddWithValue("colorid", colorId);
                c.Parameters.AddWithValue("orgid", orgId);
                c.Parameters.AddWithValue("logousageid", logoUsageId);

                using (var r = c.ExecuteReader(System.Data.CommandBehavior.SingleRow)) {
                    if (!r.HasRows)
                    {
                        return(null);            //No results?
                    }
                    r.Read();

                    /*NickName	Description	IsDarkColor	Description X1	Y1	X2	Y2	X3	Y3	X4	Y4
                     * CampusCloz	Alumni 1	1	Full Chest 309	289	705	289	309	384	705	384	*/
                    /*
                     * So working through this example which has real values from the NEW sample db I provided:
                     * · designid=3233 locates for us LogoDesignMap.ID=3233 which represents a 'Alumni 1' logo design for Org=Campus Cloz in the Full Chest position.
                     * · mastid=9464, colorid=1577, and Logo Position=Full Chest are used to locate LogoImage2.ID=63392. Now we know the source product image (1020_99_z.jpg), coordinates for the logo, and the logo position (this answers your question).
                     * · colorid=1577 tells us the color is a dark color (Color.IsDarkColor=1). We need to know if color is light or dark because we put white logos on dark colors only, and dark logos on light colors only.
                     * Now we know enough to build the logo filename. This was described in earlier email, but I'll repeat:
                     * Our logo image file names will use a strict naming convention i.e. [Organization.NickName]_[Logo Design Name]_[Light or Dark]_[Logo Position].png,
                     * i.e. CampusCloz_athletics9_light_leftsleeve.png. So, the logo image name should be: CampusCloz_athletics1_dark_FullChest.png. Note we collapse spaces in these file names, i.e. 'Campus Cloz' becomes 'CampusCloz', 'Athletics 1' -> 'Athletics1, 'Full Chest' -> FullChest
                     *
                     * */


                    //Build overlay path
                    Overlay       o = new Overlay();
                    StringBuilder p = new StringBuilder();
                    //p.AppendFormat("{4}/{0}_{1}_{2}_{3}.png", r.GetString(0), r.GetString(1), r.GetBoolean(2) ? "dark" : "light", r.GetString(3), this.OverlayBasePath.TrimEnd('/'));
                    p.AppendFormat("{4}/{0}/LogoImages/{0}_{1}_{2}_{3}.png", r.GetString(0), r.GetString(1), r.GetBoolean(2) ? "dark" : "light", r.GetString(3), this.OverlayBasePath.TrimEnd('/'));
                    p.Replace(" ", "");
                    o.OverlayPath = p.ToString();

                    //Parse logo position and use it to fill in magic values
                    string       logoPosition = r.GetString(3).Replace(" ", "");
                    LogoPosition type         = (LogoPosition)Enum.Parse(typeof(LogoPosition), logoPosition, true);
                    this.ApplyLogoPositionMagicValues(o, type);


                    o.Align = (ContentAlignment)r.GetInt32(12);     //LogoAlignment



                    //Store coordinates
                    o.Poly = new PointF[4];
                    for (int i = 0; i < 4; i++)
                    {
                        int x = r.GetInt32(4 + (i * 2));
                        int y = r.GetInt32(5 + (i * 2));
                        o.Poly[i] = new PointF(x, y);
                    }

                    return(o);
                }
            }
        }