         }
         else if (!isNaN(width))
         {
-            return calcUBoundsToFitTBoundsWidth(width, matrix,
-                                                preferredWidth, preferredHeight, 
-                                                minWidth, minHeight, 
-                                                maxWidth, maxHeight);
+            // cases 1 and 2: only explicit width or explicit height is specified,
+            // so we try to find a solution with that hard constraint.
+            if (!isNaN(explicitWidth) && isNaN(explicitHeight))
+            {
+                actualSize = calcUBoundsToFitTBoundsWidth(width, matrix,
+                                                          explicitWidth, preferredHeight, 
+                                                          explicitWidth, minHeight, 
+                                                          explicitWidth, maxHeight);
+                
+                if (actualSize)
+                    return actualSize;
+            }
+            else if (isNaN(explicitWidth) && !isNaN(explicitHeight))
+            {
+                actualSize = calcUBoundsToFitTBoundsWidth(width, matrix,
+                                                          preferredWidth, explicitHeight, 
+                                                          minWidth, explicitHeight, 
+                                                          maxWidth, explicitHeight);
+                if (actualSize)
+                    return actualSize;
+            }
+            
+            // case 3: default case. When explicitWidth, explicitHeight are both set
+            // or not set, we use the preferred size since calcUBoundsToFitTBoundsWidth
+            // will just pick one.
+            actualSize = calcUBoundsToFitTBoundsWidth(width, matrix,
+                                                      preferredWidth, preferredHeight, 
+                                                      minWidth, minHeight, 
+                                                      maxWidth, maxHeight);
+            
+            return actualSize;
         }
         else
         {
-            return calcUBoundsToFitTBoundsHeight(height, matrix,
-                                                 preferredWidth, preferredHeight, 
-                                                 minWidth, minHeight, 
-                                                 maxWidth, maxHeight);
+            // cases 1 and 2: only explicit width or explicit height is specified,
+            // so we try to find a solution with that hard constraint.
+            if (!isNaN(explicitWidth) && isNaN(explicitHeight))
+            {
+                actualSize = calcUBoundsToFitTBoundsHeight(height, matrix,
+                                                           explicitWidth, preferredHeight, 
+                                                           explicitWidth, minHeight, 
+                                                           explicitWidth, maxHeight);
+                
+                if (actualSize)
+                    return actualSize;
+            }
+            else if (isNaN(explicitWidth) && !isNaN(explicitHeight))
+            {
+                actualSize = calcUBoundsToFitTBoundsHeight(height, matrix,
+                                                           preferredWidth, explicitHeight, 
+                                                           minWidth, explicitHeight, 
+                                                           maxWidth, explicitHeight);
+                if (actualSize)
+                    return actualSize;
+            }
+            
+            // case 3: default case. When explicitWidth, explicitHeight are both set
+            // or not set, we use the preferred size since calcUBoundsToFitTBoundsWidth
+            // will just pick one.
+            actualSize = calcUBoundsToFitTBoundsHeight(height, matrix,
+                                                       preferredWidth, preferredHeight, 
+                                                       minWidth, minHeight, 
+                                                       maxWidth, maxHeight);
+            
+            return actualSize;
         }
     }
 

     *  calculated size (x,y) transformed with <code>matrix</code> will fit in the
     *  specified <code>width</code> and <code>height</code>.
     * 
     *  @param preferredWidth Preferred width for the calculated size. If possible
     *  the function will set the calculated size width to this value.
     * 

        if (isNaN(width) && isNaN(height))
            return new Point(preferredWidth, preferredHeight);
            
        var actualSize:Point;
        
        if (!isNaN(width) && !isNaN(height))
        {
            actualSize = calcUBoundsToFitTBounds(width, height, matrix,
                                                           minWidth, minHeight, 
                                                           maxWidth, maxHeight); 
            
