Exemplo n.º 1
0
/**
 * Compute the absolute value of length pair
 *
 * \param style      Style to process
 * \param ex_size    Ex size, in ems
 * \param get        Function to read length
 * \param set        Function to write length
 * \return CSS_OK on success
 */
css_error compute_absolute_length_pair(css_computed_style *style,
		const css_hint_length *ex_size,
		uint8_t (*get)(const css_computed_style *style, 
				css_fixed *len1, css_unit *unit1,
				css_fixed *len2, css_unit *unit2),
		css_error (*set)(css_computed_style *style, uint8_t type,
				css_fixed len1, css_unit unit1,
				css_fixed len2, css_unit unit2))
{
	css_fixed length1, length2;
	css_unit unit1, unit2;
	uint8_t type;

	type = get(style, &length1, &unit1, &length2, &unit2);

	if (unit1 == CSS_UNIT_EX) {
		length1 = FMUL(length1, ex_size->value);
		unit1 = ex_size->unit;
	}

	if (unit2 == CSS_UNIT_EX) {
		length2 = FMUL(length2, ex_size->value);
		unit2 = ex_size->unit;
	}

	return set(style, type, length1, unit1, length2, unit2);
}
Exemplo n.º 2
0
/**
 * Convert an absolute CSS length to points.
 *
 * \param  length  Length to convert
 * \param  unit    Corresponding unit
 * \return	   length in points
 */
css_fixed nscss_len2pt(css_fixed length, css_unit unit)
{
	/* Length must not be relative */
	assert(unit != CSS_UNIT_EM && unit != CSS_UNIT_EX);

	switch (unit) {
	/* We assume the screen and any other output has the same dpi */
	/* 1in = DPIpx => 1px = (72/DPI)pt */
	case CSS_UNIT_PX: return FDIV(FMUL(length, F_72), nscss_screen_dpi);
	/* 1in = 72pt */
	case CSS_UNIT_IN: return FMUL(length, F_72);
	/* 1in = 2.54cm => 1cm = (72/2.54)pt */
	case CSS_UNIT_CM: return FMUL(length, 
				FDIV(F_72, FLTTOFIX(2.54)));
	/* 1in = 25.4mm => 1mm = (72/25.4)pt */
	case CSS_UNIT_MM: return FMUL(length, 
				      FDIV(F_72, FLTTOFIX(25.4)));
	case CSS_UNIT_PT: return length;
	/* 1pc = 12pt */
	case CSS_UNIT_PC: return FMUL(length, INTTOFIX(12));
	default: break;
	}

	return 0;
}
Exemplo n.º 3
0
LOCAL int Palette_GetEntry( HWND hWindow, int x, int y, BOOL fClosest )
/***********************************************************************/
{
LPPALETTE lpPalette;
RECT ClientRect;
int iRowIncr, iColIncr, iWidth, iHeight, iRows, iCols;
int iStart, iEntry, r, c;
int x1, x2, y1, y2, iMinDist, iDist, dx, dy, iClosest;
LFIXED xrate, yrate;

lpPalette = (LPPALETTE)GetWindowLong(hWindow, GWL_PALETTE);
if (!lpPalette || !lpPalette->iColors)
	return(-1);

// get ClientRect and allocate buffer for SuperBlt
GetChipLayout(hWindow, &ClientRect, &iRows, &iCols, &iRowIncr, &iColIncr, &iStart);

iWidth = RectWidth(&ClientRect);
iHeight = RectHeight(&ClientRect);

yrate = FGET(iHeight, iRows);
xrate = FGET(iWidth, iCols);

x -= ClientRect.left;
y -= ClientRect.top;
iMinDist = INT_MAX;
iClosest = -1;
for (r = 0; r < iRows; ++r)
	{
	y1 = FMUL(r, yrate);
	y2 = FMUL(r+1, yrate) - 1;
	dy = min(abs(y-y1), abs(y-y2));
	iEntry = iStart + (r * iRowIncr);
	for (c = 0; c < iCols; ++c)
		{
		if (iEntry < lpPalette->iColors || fClosest)
			{
			x1 = FMUL(c, xrate);
			x2 = FMUL(c+1, xrate) - 1;
			if (y >= y1 && y <= y2 &&
			    x >= x1 && x <= x2)
				return(iEntry);
			else if (fClosest)
				{
				dx = min(abs(x-x1), abs(x-x2));
				iDist = min(dx, dy);
				if (iDist < iMinDist)
					{
					iClosest = iEntry;
					iMinDist = iDist;
					}
				}
			}
		iEntry += iColIncr;
		}
	}
return(iClosest);
}
Exemplo n.º 4
0
/***************************************************************************
	ZoomBoundRect
		Takes sugested position and size for the zoom window in owner coords.
		Will set the inputs to allowed values.
***************************************************************************/
void ZoomBoundRect(int *x, int *y, int *width, int *height)
{
	LPIMAGE lpMyImage;
	RECT 	rZoom;
	int borderW, borderH, oldwidth, oldheight;
	LFIXED fRatio, fPreposedRatio;

	if (!hZoomWindow)
		return;

    lpMyImage = (LPIMAGE)GetImagePtr (hZoomWindow );
	if (!lpMyImage)
		return;
	// compute size or border
	GetWindowRect(hZoomWindow, &rZoom);
	oldwidth = rZoom.right - rZoom.left;
	oldheight = rZoom.bottom - rZoom.top;
	GetClientRect(hZoomWindow, &rZoom);
	borderW = oldwidth -(rZoom.right - rZoom.left);
	borderH = oldheight -(rZoom.bottom - rZoom.top);

//	GetClientRect(hOwner, &rOwner);
	// be sure the zoom widow is not larger than window
//	*width = Min(*width, rOwner.right - rOwner.left);
//	*height = Min(*height, rOwner.bottom - rOwner.top);

	// be sure aspect ratios are the same
	fPreposedRatio = FGET(*width-borderW, *height-borderH);
	fRatio = FGET(lpMyImage->npix, lpMyImage->nlin);

	// is it good enough?
	oldwidth = WHOLE(fRatio*(*height-borderH));
	if (oldwidth == (*width - borderW))
		return;
	
	if (fPreposedRatio > fRatio)
		{											// width too big
		*width = FMUL(*height-borderH, fRatio);
		*width += borderW;
		}
	else if (fPreposedRatio < fRatio)
		{												// height top big
		*height = FMUL(*width-borderW,
					FGET(lpMyImage->nlin, lpMyImage->npix));
		*height += borderH;
		}

//	*x = Bound (*x, -*width/2, rOwner.right-*width/2);
//	*y = Bound (*y, -*height/2, rOwner.bottom-*height/2);
	return;
}
Exemplo n.º 5
0
void Control2Image( LPINT lpx, LPINT lpy )
/************************************************************************/
{
    int x, y;
    LFIXED xrate, yrate;

    xrate = FGET( iImageWidth, RectWidth(&rControl) );
    yrate = FGET( iImageHeight, RectHeight(&rControl) );

    x = *lpx;
    *lpx = FMUL( x - rControl.left, xrate );
    y = *lpy;
    *lpy = FMUL( y - rControl.top, yrate );
}
Exemplo n.º 6
0
void Image2Control( LPINT lpx, LPINT lpy )
/************************************************************************/
{
    int x, y;
    LFIXED xrate, yrate;

    xrate = FGET( RectWidth(&rControl), iImageWidth );
    yrate = FGET( RectHeight(&rControl), iImageHeight );

    x = *lpx;
    *lpx = rControl.left + FMUL( x, xrate );
    y = *lpy;
    *lpy = rControl.top + FMUL( y, yrate );
}
Exemplo n.º 7
0
inline int comb::process(int input)
{
	int output;

	output = buffer[bufidx];
	undenormalise(output);

	filterstore = FMUL(output, damp2) + FMUL(filterstore, damp1);
	undenormalise(filterstore);

	buffer[bufidx] = input + FMUL(filterstore, feedback);
	if(++bufidx>=bufsize) bufidx = 0;

	return output;
}
Exemplo n.º 8
0
//************************************************************************
//				lut_draw_grid
// PARAMETERS:
//					HDC hDC- Can NOT be NULL.
//					LPRECT lpArea- The area to update.
// DESCRIPTION:
//				draws the grid at the given spacing (map coords).
//************************************************************************
LOCAL VOID lut_draw_grid(LPLUTCTL lpdata, HDC hDC, LPRECT lpArea)
//***********************************************************************
{
	LFIXED rate;
	HPEN hOldPen, hPen;
	int i, val, offset, maxval;
	int gridX = lpdata->gridX;
	int gridY = lpdata->gridY;
	RECT rArea;
	POINT	point;

	// subtract one cause we are using MoveTo, LineTo
	rArea = *lpArea;
	--rArea.right;	// we can draw on left and right pixels
	--rArea.bottom; // we can draw on top and bottom pixels
	hPen = DrawTools.GetBtnFacePen();
	hOldPen = (HPEN)SelectObject( hDC, hPen );

	// do vertical lines
	if (gridX)
	{
		maxval = RectWidth(&rArea)-1; // max x value
		rate = FGET(maxval, MAXVAL);
		offset = rArea.left;
		for (i=gridX; i<256; i+=gridX)
		{
			val = offset + FMUL(i, rate);
			MoveToEx( hDC, val, rArea.top, &point);
			// add one cause LineTo doesn't draw on endpoint
			LineTo( hDC, val, rArea.bottom+1); 
		}
	}
	// do horizontal lines
	if (gridY)
	{
		maxval = RectHeight(&rArea)-1; // max y value
		rate = FGET(maxval, MAXVAL);
		offset = rArea.bottom;
		for (i=gridY; i<256; i+=gridY)
		{
			val = offset - FMUL(i, rate);
			MoveToEx( hDC, rArea.left, val, &point);
			// add one cause LineTo doesn't draw on endpoint
			LineTo( hDC, rArea.right+1, val);
		}
	}
	SelectObject( hDC, hOldPen );
}
Exemplo n.º 9
0
/* exported function documented in render/font_internal.h */
void font_plot_style_from_css(const css_computed_style *css,
		plot_font_style_t *fstyle)
{
	lwc_string **families;
	css_fixed length = 0;
	css_unit unit = CSS_UNIT_PX;
	css_color col;

	fstyle->family = plot_font_generic_family(
			css_computed_font_family(css, &families));

	css_computed_font_size(css, &length, &unit);
	fstyle->size = FIXTOINT(FMUL(nscss_len2pt(length, unit),
				      INTTOFIX(FONT_SIZE_SCALE)));

	/* Clamp font size to configured minimum */
	if (fstyle->size < (nsoption_int(font_min_size) * FONT_SIZE_SCALE) / 10)
		fstyle->size = (nsoption_int(font_min_size) * FONT_SIZE_SCALE) / 10;

	fstyle->weight = plot_font_weight(css_computed_font_weight(css));
	fstyle->flags = plot_font_flags(css_computed_font_style(css),
			css_computed_font_variant(css));

	css_computed_color(css, &col);
	fstyle->foreground = nscss_color_to_ns(col);
	fstyle->background = 0;
}
Exemplo n.º 10
0
void View1TO1()
   {
   int x, y, res, ratio;
   LFIXED fixed;
   HDC hDC;
   HWND hWnd;
   LPDISPLAY lpDisplay;
   LPIMAGE lpImage;

	if (hWnd = GetActiveDoc())
      {
	   lpImage = GetImagePtr(hWnd);
	   lpDisplay = GetDisplayPtr(hWnd);
	   hDC = GetDC( PictPubApp.Get_hWndAstral() );
	   x = GetDeviceCaps( hDC, HORZRES ); // in pixels
	   ReleaseDC( PictPubApp.Get_hWndAstral(), hDC );
	   fixed = FGET( FUNITY, Control.ScreenWidth );
	   if (res = FMUL( x, fixed)) // in pixels/inch
         {
	      ratio = ( 100L * res ) / FrameResolution(ImgGetBaseEditFrame(lpImage));
	      x = ( lpDisplay->FileRect.left 
		   + lpDisplay->FileRect.right ) / 2;
	      y = ( lpDisplay->FileRect.top 
		   + lpDisplay->FileRect.bottom ) / 2;
	      Zoom( hWnd, x, y, ratio, NO, View.ZoomWindow );
         }
      }
   }
Exemplo n.º 11
0
/**
 * Compute an absolute border side width
 *
 * \param style      Style to process
 * \param ex_size    Ex size, in ems
 * \param get        Function to read length
 * \param set        Function to write length
 * \return CSS_OK on success
 */
css_error compute_absolute_border_side_width(css_computed_style *style,
		const css_hint_length *ex_size,
		uint8_t (*get)(const css_computed_style *style, 
				css_fixed *len, css_unit *unit),
		css_error (*set)(css_computed_style *style, uint8_t type,
				css_fixed len, css_unit unit))
{
	css_fixed length;
	css_unit unit;
	uint8_t type;

	type = get(style, &length, &unit);
	if (type == CSS_BORDER_WIDTH_THIN) {
		length = INTTOFIX(1);
		unit = CSS_UNIT_PX;
	} else if (type == CSS_BORDER_WIDTH_MEDIUM) {
		length = INTTOFIX(2);
		unit = CSS_UNIT_PX;
	} else if (type == CSS_BORDER_WIDTH_THICK) {
		length = INTTOFIX(4);
		unit = CSS_UNIT_PX;
	}

	if (unit == CSS_UNIT_EX) {
		length = FMUL(length, ex_size->value);
		unit = ex_size->unit;
	}

	return set(style, CSS_BORDER_WIDTH_WIDTH, length, unit);
}
Exemplo n.º 12
0
void CSizeImageDlg::OnOK()
{
    if ( (FMUL( m_Resolution, m_Width ) > MAX_IMAGE_WIDTH) ||
       (FMUL( m_Resolution, m_Height) > MAX_IMAGE_HEIGHT))
    {
        Message( IDS_ETOOWIDE );
        OnCancel();            
        return;
    }
	SetUnitResolution( 0 );
	SetUnitInfo((UNIT_TYPE)(m_Units-IDC_PREF_UNITINCHES), m_UnitRes, m_Points);

    PostDoModal();

    CPPViewModalDlg::OnOK();
}
Exemplo n.º 13
0
LOCAL BOOL size_image(LPIMAGE lpImage, LFIXED Width , LFIXED Height, 
	int Resolution, BOOL bSmartSize)
{
	int pix, lin, res;
	LPFRAME lpDataFrame;
	LPFRAME lpAlphaFrame;
	LPOBJECT lpBase;
	LPALPHA lpAlpha;
	RECT rAlpha;
	
	if (!lpImage)
		return(FALSE);
	lpBase = ImgGetBase(lpImage);
	lpAlpha = lpBase->lpAlpha;
	res = Resolution;

	ProgressBegin(1, 0);
	pix = FMUL( res, Width );
	lin = FMUL( res, Height );
	lpAlphaFrame = NULL;
	if (lpDataFrame = SizeFrame(lpBase->Pixmap.EditFrame, pix, lin, res,
								bSmartSize))
	{
		if (lpAlpha)
			lpAlphaFrame = SizeFrame(lpAlpha->Pixmap.EditFrame, pix, lin,
									res, bSmartSize);
	}
	
	if ( !lpDataFrame || (lpAlpha && !lpAlphaFrame))
	{
		if (lpDataFrame)
			FrameClose(lpDataFrame);
		if (lpAlphaFrame)
			FrameClose(lpAlphaFrame);
		ProgressEnd();
		return( FALSE );
	}
	
	lpBase->rObject.right = FrameXSize(lpDataFrame)-1;
	lpBase->rObject.bottom = FrameYSize(lpDataFrame)-1;
	if (lpAlpha)
		MaskRectUpdate(lpAlpha, &rAlpha);
	ProgressEnd();
	
	return( TRUE );
}
Exemplo n.º 14
0
/**
 * Compute absolute clip
 *
 * \param style      Style to process
 * \param ex_size    Ex size in ems
 * \return CSS_OK on success
 */
css_error compute_absolute_clip(css_computed_style *style,
		const css_hint_length *ex_size)
{
	css_computed_clip_rect rect = { 0, 0, 0, 0, CSS_UNIT_PX, CSS_UNIT_PX,
			CSS_UNIT_PX, CSS_UNIT_PX, false, false, false, false };
	css_error error;

	if (get_clip(style, &rect) == CSS_CLIP_RECT) {
		if (rect.top_auto == false) {
			if (rect.tunit == CSS_UNIT_EX) {
				rect.top = FMUL(rect.top, ex_size->value);
				rect.tunit = ex_size->unit;
			}
		}

		if (rect.right_auto == false) {
			if (rect.runit == CSS_UNIT_EX) {
				rect.right = FMUL(rect.right, ex_size->value);
				rect.runit = ex_size->unit;
			}
		}

		if (rect.bottom_auto == false) {
			if (rect.bunit == CSS_UNIT_EX) {
				rect.bottom = FMUL(rect.bottom, ex_size->value);
				rect.bunit = ex_size->unit;
			}
		}

		if (rect.left_auto == false) {
			if (rect.lunit == CSS_UNIT_EX) {
				rect.left = FMUL(rect.left, ex_size->value);
				rect.lunit = ex_size->unit;
			}
		}

		error = set_clip(style, CSS_CLIP_RECT, &rect);
		if (error != CSS_OK)
			return error;
	}

	return CSS_OK;
}
Exemplo n.º 15
0
/*===========================================================================
   This function format double num to AECHAR, 3 pos hold
===========================================================================*/
AECHAR* TS_FLT2SZ_3(AECHAR* szBuf, double val)
{
#if 1
	double tmp = 0, tt = 0, min = 0;
	int d = 0, m = 0;
	int zero_pad = 0;
	char strZero[4];
	AECHAR szZero[16];

	if (szBuf == NULL)
		return NULL;

	tmp = FABS(val);
	if (FCMP_GE(tmp, 0.001))
	{
		tt = FFLOOR(tmp);
		d = FLTTOINT(tt);
		m = FLTTOINT(FMUL(FSUB(tmp, tt), 10000.0));
		m = (m % 10 >= 5) ? (m + 10) / 10 : m / 10;
		if (m > 0)
		{
			if (m < 100)	//0.012
			{
				zero_pad++;
			}

			if (m < 10)	    //0.001
			{
				zero_pad++;
			}

			//补充后面的0
			if (zero_pad > 0)
			{
				STRNCPY(strZero, "000", zero_pad);
				strZero[zero_pad] = 0;
				STRTOWSTR(strZero, szZero, 16);
			}
		}
	}
	else
	{
		d = 0;
		m = 0;
	}

	if (zero_pad > 0)
		WSPRINTF(szBuf, 32, L"%d.%s%d", d, szZero, m);
	else
		WSPRINTF(szBuf, 32, L"%d.%d", d, m);
	return szBuf;
#else
	FLOATTOWSTR(val, szBuf, 32);
#endif
}
Exemplo n.º 16
0
LOCAL BOOL Palette_SelectRect(HWND hWindow, int iSelect, LPRECT lpSelectRect)
/***********************************************************************/
{
RECT ClientRect;
int iRowIncr, iColIncr, iWidth, iHeight, iRows, iCols;
int iStart, iEntry, r, c;
LFIXED xrate, yrate;
LPPALETTE lpPalette;

lpPalette = (LPPALETTE)GetWindowLong(hWindow, GWL_PALETTE);
if (!lpPalette || !lpPalette->iColors)
	return(FALSE);

// get ClientRect and allocate buffer for SuperBlt
GetChipLayout(hWindow, &ClientRect, &iRows, &iCols, &iRowIncr, &iColIncr, &iStart);

iWidth = RectWidth(&ClientRect);
iHeight = RectHeight(&ClientRect);

yrate = FGET(iHeight, iRows);
xrate = FGET(iWidth, iCols);

for (r = 0; r < iRows; ++r)
	{
	iEntry = iStart + (r * iRowIncr);
	for (c = 0; c < iCols; ++c)
		{
		if (iEntry == iSelect)
			{
			lpSelectRect->top = ClientRect.top + FMUL(r, yrate);
			lpSelectRect->bottom = ClientRect.top + FMUL(r+1, yrate) - 1;
			lpSelectRect->left = ClientRect.left + FMUL(c, xrate);
			lpSelectRect->right = ClientRect.left + FMUL(c+1, xrate) - 1;
			return(TRUE);
			}
		iEntry += iColIncr;
		}
	}
return(FALSE);
}
Exemplo n.º 17
0
LOCAL  void PalPicker_GetRect( HWND hWindow, int r, int c, LPRECT lpRect)
/***********************************************************************/
{
RECT ClientRect;
int iWidth, iHeight;
LFIXED xrate, yrate;

GetClientRect(hWindow, &ClientRect);
InflateRect(&ClientRect, -3, -3);
WindowsToAstralRect(&ClientRect);

iWidth = RectWidth(&ClientRect);
iHeight = RectHeight(&ClientRect);

yrate = FGET(iHeight, 16);
xrate = FGET(iWidth, 16);

lpRect->left = FMUL(c, xrate) + 1;
lpRect->right = FMUL(c+1, xrate) - 2;
lpRect->top = FMUL(r, yrate) + 1;
lpRect->bottom = FMUL(r+1, yrate) - 2;
OffsetRect(lpRect, ClientRect.left, ClientRect.top);
}
Exemplo n.º 18
0
BOOL CanZoom( HWND hWnd, LFIXED FileRate, LPRECT lpFileRect,
               LPRECT lpDispRect )
/************************************************************************/
{
LFIXED DispRate;
long lFileWidth, lFileHeight;
int iDispWidth, iDispHeight;
LPIMAGE lpImage;

lpImage = GetImagePtr(hWnd);
if (FileRate != 0)  // FileRate passed in
    DispRate = FGET(FUNITY, FileRate);
else        // Displaying a FileRect
    {
    // calculate DispRate using this FileRect and
    // DispRect.
    iDispWidth = RectWidth(lpDispRect);
    iDispHeight = RectHeight(lpDispRect);
    DispRate = ScaleToFit(&iDispWidth, &iDispHeight,
                RectWidth(lpFileRect),
                RectHeight(lpFileRect));
    }
// Calculate eventual size in File coordinates using
// this DispRate.  This calculation is done by most
// of the viewing routines and has the possibility
// of overflow.  Usually in these routines when the
// calculation is made it is too late to turn back
// so those routines call CanZoom() before doing
// anything that is unreversible.
lFileWidth = FMUL(lpImage->npix, DispRate);
lFileHeight = FMUL(lpImage->nlin, DispRate);
// Although MAXINT is 32767, I decided to use 30000 just
// for some slop and my own paranoia
return(lFileWidth > 0L && lFileWidth <= MAX_IMAGE_WIDTH &&
       lFileHeight > 0L && lFileHeight <= MAX_IMAGE_HEIGHT);
}
Exemplo n.º 19
0
/**
 * Compute the absolute value of length
 *
 * \param style      Style to process
 * \param ex_size    Ex size, in ems
 * \param get        Function to read length
 * \param set        Function to write length
 * \return CSS_OK on success
 */
css_error compute_absolute_length(css_computed_style *style,
		const css_hint_length *ex_size,
		uint8_t (*get)(const css_computed_style *style, 
				css_fixed *len, css_unit *unit),
		css_error (*set)(css_computed_style *style, uint8_t type,
				css_fixed len, css_unit unit))
{
	css_fixed length;
	css_unit unit;
	uint8_t type;

	type = get(style, &length, &unit);

	if (unit == CSS_UNIT_EX) {
		length = FMUL(length, ex_size->value);
		unit = ex_size->unit;
	}

	return set(style, type, length, unit);
}
Exemplo n.º 20
0
/**
 * Compute absolute line-height
 *
 * \param style      Style to process
 * \param ex_size    Ex size, in ems
 * \return CSS_OK on success
 */
css_error compute_absolute_line_height(css_computed_style *style,
		const css_hint_length *ex_size)
{
	css_fixed length = 0;
	css_unit unit = CSS_UNIT_PX;
	uint8_t type;
	css_error error;

	type = get_line_height(style, &length, &unit);

	if (type == CSS_LINE_HEIGHT_DIMENSION) {
		if (unit == CSS_UNIT_EX) {
			length = FMUL(length, ex_size->value);
			unit = ex_size->unit;
		}

		error = set_line_height(style, type, length, unit);
		if (error != CSS_OK)
			return error;
	}

	return CSS_OK;
}
Exemplo n.º 21
0
/**
 * Compute absolute vertical-align
 *
 * \param style      Style to process
 * \param ex_size    Ex size, in ems
 * \return CSS_OK on success
 */
css_error compute_absolute_vertical_align(css_computed_style *style,
		const css_hint_length *ex_size)
{
	css_fixed length = 0;
	css_unit unit = CSS_UNIT_PX;
	uint8_t type;
	css_error error;

	type = get_vertical_align(style, &length, &unit);

	if (type == CSS_VERTICAL_ALIGN_SET) {
		if (unit == CSS_UNIT_EX) {
			length = FMUL(length, ex_size->value);
			unit = ex_size->unit;
		}

		error = set_vertical_align(style, type, length, unit);
		if (error != CSS_OK)
			return error;
	}

	return CSS_OK;
}
Exemplo n.º 22
0
/**
 * Compute the absolute value of length or normal
 *
 * \param style      Style to process
 * \param ex_size    Ex size, in ems
 * \param get        Function to read length
 * \param set        Function to write length
 * \return CSS_OK on success
 */
css_error compute_absolute_length_normal(css_computed_style *style,
		const css_hint_length *ex_size,
		uint8_t (*get)(const css_computed_style *style, 
				css_fixed *len, css_unit *unit),
		css_error (*set)(css_computed_style *style, uint8_t type,
				css_fixed len, css_unit unit))
{
	css_fixed length;
	css_unit unit;
	uint8_t type;

	type = get(style, &length, &unit);
	if (type != CSS_LETTER_SPACING_NORMAL) {
		if (unit == CSS_UNIT_EX) {
			length = FMUL(length, ex_size->value);
			unit = ex_size->unit;
		}

		return set(style, CSS_LETTER_SPACING_SET, length, unit);
	}

	return set(style, CSS_LETTER_SPACING_NORMAL, 0, CSS_UNIT_PX);
}
Exemplo n.º 23
0
css_error compute_font_size(void *pw, const css_hint *parent, css_hint *size)
{
	static css_hint_length sizes[] = {
		{ FLTTOFIX(6.75), CSS_UNIT_PT },
		{ FLTTOFIX(7.50), CSS_UNIT_PT },
		{ FLTTOFIX(9.75), CSS_UNIT_PT },
		{ FLTTOFIX(12.0), CSS_UNIT_PT },
		{ FLTTOFIX(13.5), CSS_UNIT_PT },
		{ FLTTOFIX(18.0), CSS_UNIT_PT },
		{ FLTTOFIX(24.0), CSS_UNIT_PT }
	};
	const css_hint_length *parent_size;

	UNUSED(pw);

	/* Grab parent size, defaulting to medium if none */
	if (parent == NULL) {
		parent_size = &sizes[CSS_FONT_SIZE_MEDIUM - 1];
	} else {
		assert(parent->status == CSS_FONT_SIZE_DIMENSION);
		assert(parent->data.length.unit != CSS_UNIT_EM);
		assert(parent->data.length.unit != CSS_UNIT_EX);
		parent_size = &parent->data.length;
	}

	assert(size->status != CSS_FONT_SIZE_INHERIT);

	if (size->status < CSS_FONT_SIZE_LARGER) {
		/* Keyword -- simple */
		size->data.length = sizes[size->status - 1];
	} else if (size->status == CSS_FONT_SIZE_LARGER) {
		/** \todo Step within table, if appropriate */
		size->data.length.value = 
				FMUL(parent_size->value, FLTTOFIX(1.2));
		size->data.length.unit = parent_size->unit;
	} else if (size->status == CSS_FONT_SIZE_SMALLER) {
		/** \todo Step within table, if appropriate */
		size->data.length.value = 
				FMUL(parent_size->value, FLTTOFIX(1.2));
		size->data.length.unit = parent_size->unit;
	} else if (size->data.length.unit == CSS_UNIT_EM ||
			size->data.length.unit == CSS_UNIT_EX) {
		size->data.length.value = 
			FMUL(size->data.length.value, parent_size->value);

		if (size->data.length.unit == CSS_UNIT_EX) {
			size->data.length.value = FMUL(size->data.length.value,
					FLTTOFIX(0.6));
		}

		size->data.length.unit = parent_size->unit;
	} else if (size->data.length.unit == CSS_UNIT_PCT) {
		size->data.length.value = FDIV(FMUL(size->data.length.value,
				parent_size->value), FLTTOFIX(100));
		size->data.length.unit = parent_size->unit;
	}

	size->status = CSS_FONT_SIZE_DIMENSION;

	return CSS_OK;
}
Exemplo n.º 24
0
BOOL CSizeImageDlg::DoSizeControls( ITEMID id, UINT codeNotify, BOOL bResAdjust )
{
    BOOL bResult = TRUE;
    HWND hDlg = GetSafeHwnd();
    BOOL Bool;
    long x, y;
    int npix, nlin;
    HWND hWnd, hControl;
    RECT rArea;
    LFIXED scale;
    LPIMAGE lpImage;
    FRMDATATYPE Type;

    lpImage = GetImage();
    ImgGetInfo(lpImage, NULL, NULL, NULL, &Type);
    npix = CROPWIDTH();
    nlin = CROPHEIGHT();

    switch( id )
    {
	    case IDC_SMARTSIZE:
	        m_SmartSize = !m_SmartSize;
	        CheckDlgButton( IDC_SMARTSIZE, m_SmartSize );
            break;

	    case IDC_MAINTAINSIZE:
	        m_MaintainSize = !m_MaintainSize;
	        if (m_MaintainSize)
		        m_Distortable = NO;

	        ControlEnable(hDlg, IDC_DISTORT, !m_MaintainSize);
	        ControlEnable(hDlg, IDC_SMARTSIZE, !m_MaintainSize);
	        Bool = !m_MaintainSize || m_Units != IDC_PREF_UNITPIXELS;
	        ControlEnable(hDlg, IDC_WIDTH, Bool);
	        ControlEnable(hDlg, IDC_HEIGHT, Bool);
	        ControlEnable(hDlg, IDC_SCALEX, Bool);
	        ControlEnable(hDlg, IDC_SCALEY, Bool);

	        if (m_MaintainSize)
	        {
		        m_Resolution = m_CropResolution = m_OrigResolution;
		        m_Width  = FGET( npix, m_CropResolution );
		        m_Height = FGET( nlin, m_CropResolution );
		        SetUnitResolution( m_CropResolution );
		        SetDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO );
		        SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES );
		        SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES );
	        }
	        CheckDlgButton( IDC_MAINTAINSIZE, m_MaintainSize );
	        CheckDlgButton( IDC_SMARTSIZE, !m_MaintainSize && m_SmartSize );
	        break;

	    case IDC_PREF_UNITS:
			{
			WORD wUnits;				
	        if ( !(wUnits = HandleCombo( hDlg, id, codeNotify )) )
		        break;
	        
			m_Units = wUnits;
	        SetUnitInfo((UNIT_TYPE)(m_Units-IDC_PREF_UNITINCHES), m_UnitRes, 
                m_Points);
	        CheckComboItem(hDlg, IDC_PREF_UNITS, IDC_PREF_UNITFIRST,
		        IDC_PREF_UNITLAST, m_Units);

	        Bool = !m_MaintainSize || m_Units != IDC_PREF_UNITPIXELS;
	        ControlEnable(hDlg, IDC_WIDTH, Bool);
	        ControlEnable(hDlg, IDC_HEIGHT, Bool);
	        ControlEnable(hDlg, IDC_SCALEX, Bool);
	        ControlEnable(hDlg, IDC_SCALEY, Bool);

	        if (m_MaintainSize && m_Units == IDC_PREF_UNITPIXELS)
	        {
		        m_CropResolution = m_Resolution;
		        SetUnitResolution( m_CropResolution );
		        m_Width  = FGET( npix, m_CropResolution );
		        m_Height = FGET( nlin, m_CropResolution );
		        y = FMUL( m_CropResolution, m_Height );
		        m_ScaleY = ((y*100L) + nlin/2) / nlin;
		        SetDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, NO );
		        x = FMUL( m_CropResolution, m_Width );
		        m_ScaleX = ((x*100L) + npix/2) / npix;
		        SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO );
	        }
	       	SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES );
	       	SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES );
	        SetUnitLabels();
			}
	        break;

        case IDC_DISTORT:
	        m_Distortable = !m_Distortable;
	        CheckDlgButton( IDC_DISTORT, m_Distortable );
	        if (m_Distortable)
		        m_MaintainSize = NO;
	        ControlEnable(hDlg, IDC_MAINTAINSIZE, !m_MaintainSize);
	        if ( m_ScaleX != m_ScaleY )
	        {
		        m_ScaleX = m_ScaleY;
		        x = (((long)npix * m_ScaleX)+50L)/100L;
		        m_Width  = FGET( x, m_CropResolution );
		        SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES );
		        SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO );
	        }
	        CheckDlgButton( IDC_SMARTSIZE,m_SmartSize && !m_Distortable);
	        ControlEnable( hDlg, IDC_SMARTSIZE, !m_Distortable && CANDOTRANSPARENCY(Type));
	        ControlEnable(hDlg, IDC_MAINTAINSIZE, !m_Distortable && lpImage);
	        if ( Page.PrintNumeric )
		        break;
	        if ( !(hWnd = ::GetDlgItem( hDlg,IDC_PRINTVIEWPAGE)) )
		        break;
	        if ( !(hControl = ::GetDlgItem( hDlg,IDC_PRINTVIEWIMAGE)) )
		        break;
	        SetLongBit(hControl, GWL_STYLE, IS_RATIO_CONSTRAIN,
		        !m_Distortable );
	        if (!m_Distortable)
	        {
		        ::GetWindowRect(hControl, &rArea);
		        ::ScreenToClient(hWnd, (LPPOINT)&rArea.left);
		        ::ScreenToClient(hWnd, (LPPOINT)&rArea.right);
		        ::MoveWindow(hControl, rArea.left, rArea.top,
			        RectWidth(&rArea)-1, RectHeight(&rArea)-1, TRUE);
	        }
	        break;

        case IDC_HEIGHT:
	        if ( ::GetFocus() != ::GetDlgItem( hDlg,id ) )
		        break;
	        if ( codeNotify != EN_CHANGE )
		        break;
	        m_Height = GetDlgItemSpinFixed( hDlg, IDC_HEIGHT, &Bool, YES);
	        if (m_MaintainSize)
	        {
		        scale = FGET(FUNITY, m_Height);
		        m_Resolution = FMUL(nlin, scale);
		        SetUnitResolution( m_Resolution );
		        SetDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO );
	        }
	        // y = number of new pixels x 100
	        y = FMUL( m_CropResolution, m_Height );
	        // calculate scale factor = (new pixels * 100) / old pixels
	        m_ScaleY = ((y * 100L) + nlin/2) / nlin;
	        SetDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, NO );
	        if ( !m_Distortable )
	        {
		        m_ScaleX = m_ScaleY;
				x = (((long)npix * (long)y) + (nlin/2))/ (long)nlin;
		        m_Width  = FGET( x, m_CropResolution );
		        SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES );
		        SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO );
	        }
	        ImageMemory( hDlg, IDC_MEMORY,
			        m_MaintainSize ? FGET(npix,1) : m_Width,
			        m_MaintainSize ? FGET(nlin,1) : m_Height,
			        m_MaintainSize ? 1 : m_Resolution, m_Depth );
	        break;

        case IDC_WIDTH:
	        if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) )
		        break;
	        if ( codeNotify != EN_CHANGE )
		        break;
	        m_Width = GetDlgItemSpinFixed( hDlg, IDC_WIDTH, &Bool, YES );
	        if (m_MaintainSize)
	        {
		        scale = FGET(FUNITY, m_Width);
		        m_Resolution = FMUL(npix, scale);
		        SetUnitResolution( m_Resolution );
		        SetDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO );
	        }
	        x = FMUL( m_CropResolution, m_Width );
	        m_ScaleX = ((x * 100L) + npix/2L) / (long)npix;
	        SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO );
	        if ( !m_Distortable )
	        {
				m_ScaleY = m_ScaleX;
				y = (((long)nlin * (long)x) + (npix/2))/ (long)npix;
		        m_Height  = FGET( y, m_CropResolution );
		        SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES );
		        SetDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, NO );
	        }
	        ImageMemory( hDlg, IDC_MEMORY,
			        m_MaintainSize ? FGET(npix,1) : m_Width,
			        m_MaintainSize ? FGET(nlin,1) : m_Height,
			        m_MaintainSize ? 1 : m_Resolution, m_Depth );
	        break;

        case IDC_RES:
	        if ( ::GetFocus() != ::GetDlgItem( hDlg, id ) )
		        break;
	        if ( codeNotify != EN_CHANGE )
		        break;
	        m_Resolution = GetDlgItemSpin( hDlg, IDC_RES, &Bool, NO );
	        if ( m_Resolution <= 0 )
		        m_Resolution = 2;
	        if (m_MaintainSize)
	        {
		        m_Width = FGET(npix, m_Resolution);
		        m_Height = FGET(nlin, m_Resolution);
		        SetUnitResolution( m_Resolution );
		        if (m_Units != IDC_PREF_UNITPIXELS)
		        {
			        SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES );
			        SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES );
			        y = FMUL( m_CropResolution, m_Height );
			        m_ScaleY = ((y*100L) + nlin/2) / nlin;
			        SetDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, NO );
			        x = FMUL( m_CropResolution, m_Width );
			        m_ScaleX = ((x*100L) + npix/2) / npix;
			        SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO );
		        }
	        }
	
	        if ( m_Units == IDC_PREF_UNITPIXELS )
            {
	            if ( bResAdjust )
                { // Extract the values again (inch values changed)
			        m_CropResolution = m_Resolution;
			        SetUnitResolution( m_Resolution );
			        ::SetFocus( hWnd = ::GetDlgItem( hDlg,IDC_HEIGHT ) );
					FORWARD_WM_COMMAND(hDlg, IDC_HEIGHT, hWnd, EN_CHANGE,
									   ::SendMessage);
			        ::SetFocus( hWnd = ::GetDlgItem( hDlg,IDC_WIDTH ) );
					FORWARD_WM_COMMAND(hDlg, IDC_WIDTH, hWnd, EN_CHANGE,
									   ::SendMessage);
			        ::SetFocus( ::GetDlgItem( hDlg,id ) );
		        }
	            else
		        { // Change the edit box
			        SetUnitResolution( m_Resolution );
			        SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES);
			        SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES );
		        }
            }
	        ImageMemory( hDlg, IDC_MEMORY,
			        m_MaintainSize ? FGET(npix,1) : m_Width,
			        m_MaintainSize ? FGET(nlin,1) : m_Height,
			        m_MaintainSize ? 1 : m_Resolution, m_Depth );
	        break;

        case IDC_SCALEX:
	        if ( GetFocus() != GetDlgItem( id ) )
		        break;
	        if ( codeNotify != EN_CHANGE )
		        break;
	        m_ScaleX = GetDlgItemSpin( hDlg, IDC_SCALEX, &Bool, NO );
	        x = (((long)npix * m_ScaleX)+50L)/100L;
	        m_Width  = FGET( x, m_CropResolution );
	        SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES );
	        if (m_MaintainSize)
	        {
		        scale = FGET(FUNITY, m_Width);
		        m_Resolution = FMUL(npix, scale);
		        SetUnitResolution( m_Resolution );
		        SetDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO );
	        }
	        if ( !m_Distortable )
	        {
		        m_ScaleY = m_ScaleX;
		        y = (((long)nlin * m_ScaleY)+50)/100L;
		        m_Height  = FGET( y, m_CropResolution );
		        SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES );
		        SetDlgItemSpin( hDlg, IDC_SCALEY, m_ScaleY, NO );
	        }
	        ImageMemory( hDlg, IDC_MEMORY,
			        m_MaintainSize ? FGET(npix,1) : m_Width,
			        m_MaintainSize ? FGET(nlin,1) : m_Height,
			        m_MaintainSize ? 1 : m_Resolution, m_Depth );
	        break;

        case IDC_SCALEY:
	        if ( GetFocus() != GetDlgItem( id ) )
		        break;
	        if ( codeNotify != EN_CHANGE )
		        break;
	        m_ScaleY = GetDlgItemSpin( hDlg, IDC_SCALEY, &Bool, NO );
	        y = (((long)nlin * m_ScaleY)+50)/100L;
	        m_Height = FGET( y, m_CropResolution );
	        SetDlgItemSpinFixed( hDlg, IDC_HEIGHT, m_Height, YES );
	        if (m_MaintainSize)
	        {
		        scale = FGET(FUNITY, m_Height);
		        m_Resolution = FMUL(nlin, scale);
		        SetUnitResolution( m_Resolution );
		        SetDlgItemSpin( hDlg, IDC_RES, m_Resolution, NO );
	        }
	        if ( !m_Distortable )
	        {
		        m_ScaleX = m_ScaleY;
		        x = (((long)npix * m_ScaleX)+50L)/100L;
		        m_Width  = FGET( x, m_CropResolution );
		        SetDlgItemSpinFixed( hDlg, IDC_WIDTH, m_Width, YES);
		        SetDlgItemSpin( hDlg, IDC_SCALEX, m_ScaleX, NO );
	        }
	        ImageMemory( hDlg, IDC_MEMORY,
			        m_MaintainSize ? FGET(npix,1) : m_Width,
			        m_MaintainSize ? FGET(nlin,1) : m_Height,
			        m_MaintainSize ? 1 : m_Resolution, m_Depth );
	        break;

        case IDC_MEMORY:
        default:
            bResult = FALSE;
    	    break;
    }
    return bResult;        
}
Exemplo n.º 25
0
BOOL ScrollImage( HWND hWnd, BOOL fVScroll, UINT code, int pos )
/************************************************************************/
{
int fy, dy, fx, dx;
RECT rScroll;
BOOL bScrollWindow;
#define SCROLLPIXELS 10
LPIMAGE lpImage;
LPDISPLAY lpDisplay;

lpImage = GetImagePtr(hWnd);
lpDisplay = GetDisplayPtr(hWnd);

if (IsIconic(hWnd))
    return( NO );

bScrollWindow = NO;
rScroll = lpDisplay->DispRect;
rScroll.bottom++; rScroll.right++;
if (fVScroll &&
    ( lpImage->nlin - RectHeight( &lpDisplay->FileRect ) > 0 ) )
    {
    switch ( code )
        {
        case SB_ENDSCROLL:
        ScrollEnd( hWnd );
        break;

        case SB_TOP:
        case SB_BOTTOM:
        MessageBeep(0);
        break;

        case SB_PAGEUP:
        case SB_PAGEDOWN:
        case SB_LINEUP:
        case SB_LINEDOWN:
        fy = SCROLLPIXELS;
        if ( code == SB_PAGEUP || code == SB_PAGEDOWN )
            fy *= 10;
        if ( !(fy = FMUL( fy, lpDisplay->FileRate )) )
            fy = 1;
        if ( code == SB_LINEDOWN || code == SB_PAGEDOWN )
            {
            fy = -fy;
            dy = lpDisplay->FileRect.bottom - lpImage->nlin + 1;
            }
        else
        // ( code == SB_LINEUP || code == SB_PAGEUP )
            dy = lpDisplay->FileRect.top;
        if ( !dy )
            break;
        if ( abs(fy) > abs(dy) )
            fy = dy;
        if ( !(dy = FMUL( fy, lpDisplay->DispRate )) )
            break;
        ScrollStart( hWnd );
        lpDisplay->FileRect.top -= fy;
        lpDisplay->FileRect.bottom -= fy;
        lpDisplay->yDiva -= dy;
        ScrollWindow( hWnd, 0 /*x*/, dy, &rScroll, &rScroll );
        AstralUpdateWindow(hWnd);
        bScrollWindow = YES;
        break;

        case SB_THUMBPOSITION:
        case SB_THUMBTRACK:
        if ( !(fy = GetDisplayScrollDelta( hWnd, lpDisplay, SB_VERT, pos) ) )
            break;
        if ( !(dy = FMUL( fy, lpDisplay->DispRate )) )
            break;
        ScrollStart( hWnd );
        lpDisplay->FileRect.top -= fy;
        lpDisplay->FileRect.bottom -= fy;
        lpDisplay->yDiva -= dy;
        ScrollWindow( hWnd, 0 /*x*/, dy, &rScroll, &rScroll );
        AstralUpdateWindow(hWnd);
        bScrollWindow = YES;
        break;
        }
    }

if (!fVScroll &&
    ( lpImage->npix - RectWidth( &lpDisplay->FileRect ) > 0 ) )
    {
    switch ( code )
        {
        case SB_ENDSCROLL:
        ScrollEnd( hWnd );
        break;

        case SB_TOP:
        case SB_BOTTOM:
        MessageBeep(0);
        break;

        case SB_PAGEUP:
        case SB_PAGEDOWN:
        case SB_LINEUP:
        case SB_LINEDOWN:
        fx = SCROLLPIXELS;
        if ( code == SB_PAGEUP || code == SB_PAGEDOWN )
            fx *= 10;
        if ( !(fx = FMUL( fx, lpDisplay->FileRate )) )
            fx = 1;
        if ( code == SB_LINEDOWN || code == SB_PAGEDOWN )
            {
            fx = -fx;
            dx = lpDisplay->FileRect.right - lpImage->npix + 1;
            }
        else
        // ( code == SB_LINEUP || code == SB_PAGEUP )
            dx = lpDisplay->FileRect.left;
        if ( !dx )
            break;
        if ( abs(fx) > abs(dx) )
            fx = dx;
        if ( !(dx = FMUL( fx, lpDisplay->DispRate )) )
            break;
        ScrollStart( hWnd );
        lpDisplay->FileRect.left -= fx;
        lpDisplay->FileRect.right -= fx;
        lpDisplay->xDiva -= dx;
        ScrollWindow( hWnd, dx, 0 /*y*/, &rScroll, &rScroll );
        AstralUpdateWindow(hWnd);
        bScrollWindow = YES;
        break;

        case SB_THUMBPOSITION:
        case SB_THUMBTRACK:
        if ( !(fx = GetDisplayScrollDelta( hWnd, lpDisplay, SB_HORZ, pos )) )
            break;
        if ( !(dx = FMUL( fx, lpDisplay->DispRate )) )
            break;
        ScrollStart( hWnd );
        lpDisplay->FileRect.left -= fx;
        lpDisplay->FileRect.right -= fx;
        lpDisplay->xDiva -= dx;
        ScrollWindow( hWnd, dx, 0 /*y*/, &rScroll, &rScroll );
        AstralUpdateWindow(hWnd);
        bScrollWindow = YES;
        break;
        }
    }

return( bScrollWindow );
}
Exemplo n.º 26
0
void ComputeFileRect( HWND hWnd, int x, int y, LFIXED FileRate )
/************************************************************************/
{
int fx, fy, DispWidth, DispHeight, dx, dy;
LFIXED DispRate;
LPIMAGE lpImage;
LPDISPLAY lpDisplay;

// A NULL FileRate is a signal that FileRect was just initialized
// and doesn't need recalculating
if ( !FileRate)
    return;

lpImage = GetImagePtr(hWnd);
lpDisplay = GetDisplayPtr(hWnd);

// FileRect will be recomputed from FileRate and a center point (x,y)
DispWidth = RectWidth( &lpDisplay->DispRect );
DispHeight = RectHeight( &lpDisplay->DispRect );

DispRate = FGET(FUNITY, lpDisplay->FileRate);
dx = FMUL(lpImage->npix, DispRate);
dy = FMUL(lpImage->nlin, DispRate);
// FileRate == 1 is a special case for handling iconic state
// otherwise handle normally
if ( FileRate == TINYRATE) // Display all of image - iconic state
    {
    fx = lpImage->npix;
    fy = lpImage->nlin;
    lpDisplay->ViewPercentage = 0;
    }
else 
    {
    // if image fits or is smaller than display surface
    // use maximum FileRect, otherwise use current FileRate
    if (dx <= DispWidth)
        fx = lpImage->npix;
    else
        fx = FMUL( DispWidth, FileRate );
    if (dy <= DispHeight)
        fy = lpImage->nlin;
    else
        fy = FMUL( DispHeight, FileRate );
    }

if (x == -1 && y == -1) // special signal to use old XY
    {
    x = lpDisplay->FileRect.left;
    y = lpDisplay->FileRect.top;
    }
else
    {
    x -= ( fx / 2 );
    y -= ( fy / 2 );
    }
if ( x < 0 ) x = 0;
if ( y < 0 ) y = 0;
if ( x + fx - 1 >= lpImage->npix )  x = lpImage->npix - fx;
if ( y + fy - 1 >= lpImage->nlin )  y = lpImage->nlin - fy;
lpDisplay->FileRect.left   = x;
lpDisplay->FileRect.top = y;
lpDisplay->FileRect.right  = x + fx - 1;
lpDisplay->FileRect.bottom = y + fy - 1;
BoundRect( &lpDisplay->FileRect, 0, 0, lpImage->npix-1, lpImage->nlin-1 );
}
Exemplo n.º 27
0
void ComputeDispRect(HWND hWnd)
/************************************************************************/
{
int w, h, dx, dy;
int iWidth, iHeight, iImageWidth, iImageHeight;
LFIXED DispRate;
RECT DispRect;
BOOL bZoomed, bIconic;
LPIMAGE lpImage;
LPDISPLAY lpDisplay;

lpImage = GetImagePtr(hWnd);
lpDisplay = GetDisplayPtr(hWnd);

BOOL bInPlaceFrameType = FALSE;
HWND hMDIWindow = hWnd;
CWnd *pWnd = CWnd::FromHandle(hMDIWindow);
if (pWnd->IsKindOf(RUNTIME_CLASS(CServerView)))        
{
	hMDIWindow = pWnd->GetParentFrame()->GetSafeHwnd();
	bInPlaceFrameType = ((CServerView*)pWnd)->GetDocument()->IsInPlaceActive();
}

// get max size of client area with no scrollbars
GetDispRect(hWnd, &DispRect, 1, 1);
w = RectWidth(&DispRect);
h = RectHeight(&DispRect);

// If we have no FileRate to this point, it means somebody wants
// to display a specific FileRect.  Calculate a FileRate so that
// we can calculate a DispRect.  This is necessary because it is
// possible (when the window is maximized for example) that the
// FileRect requested will not fill up the window, so it would
// need to be recalculated.  It is assumed that scrollbars would
// not be needrf and should not be needed if the calculation is
// done correctly, which hopefully it is.
if (!lpDisplay->FileRate)
    {
    iWidth = w; iHeight = h;
    DispRate = ScaleToFit(&iWidth, &iHeight, RectWidth(&lpDisplay->FileRect), RectHeight(&lpDisplay->FileRect));
    lpDisplay->FileRate = FGET(FUNITY, DispRate);
    }
if (lpDisplay->FileRate == TINYRATE) // Iconic
    {
    iWidth = w;
    iHeight = h;

    iImageWidth = lpImage->npix;
    iImageHeight = lpImage->nlin;
    DispRate = ScaleToFit(&iWidth, &iHeight, iImageWidth, iImageHeight);
	//---------------------------------------------------------------------
	// NOTE!! added bInPlaceFrameType here because Insitu needs to be able 
	// to scale over 100%.
	//---------------------------------------------------------------------
	if (!bInPlaceFrameType && (DispRate > FGET(1, 1))) 
        {
        DispRate = FGET(1, 1);
        iWidth = FMUL(iImageWidth, DispRate);
        iHeight = FMUL(iImageHeight, DispRate);
        }
    }
else // if (lpDisplay->FileRate) // Specific FileRate
    {
    // Calulate how much space is needed at this FileRate
    DispRate = FGET(FUNITY, lpDisplay->FileRate);
    iImageWidth = FMUL(lpImage->npix, DispRate);
    iImageHeight = FMUL(lpImage->nlin, DispRate);

    // See if scrollbars will be necessary and get the
    // appropriate DispRect if so
    if (iImageWidth > w && iImageHeight > h)
        {
        GetDispRect(hWnd, &DispRect, 2, 2);
        }
    else
    if (iImageWidth > w)
        {
        GetDispRect(hWnd, &DispRect, 2, 1);
        h = RectHeight(&DispRect);
        if (iImageHeight > h)
            {
            GetDispRect(hWnd, &DispRect, 2, 2);
            }
        }
    else
    if (iImageHeight > h)
        {
        GetDispRect(hWnd, &DispRect, 1, 2);
        w = RectWidth(&DispRect);
        if (iImageWidth > w)
            {
            GetDispRect(hWnd, &DispRect, 2, 2);
            }
        }
    w = RectWidth(&DispRect);
    h = RectHeight(&DispRect);
    iWidth = w;
    iHeight = h;

    // Clip the DispRect size to the amount needed for image
    if (iImageWidth < iWidth)
        iWidth = iImageWidth;
    if (iImageHeight < iHeight)
        iHeight = iImageHeight;
    }

bIconic = IsIconic(hMDIWindow);
bZoomed = IsZoomed(hMDIWindow);
if (bZoomed || bIconic)
    {
    dy = RectHeight(&DispRect) - iHeight;
    dy /= 2;
    dx = RectWidth(&DispRect) - iWidth;
    dx /= 2;
    lpDisplay->DispRect.top = DispRect.top + dy;
    lpDisplay->DispRect.left = DispRect.left + dx;
    }
else
    {
    lpDisplay->DispRect.top = DispRect.top;
    lpDisplay->DispRect.left = DispRect.left;
    }
lpDisplay->DispRect.bottom = lpDisplay->DispRect.top + iHeight - 1;
lpDisplay->DispRect.right = lpDisplay->DispRect.left + iWidth - 1;
}
Exemplo n.º 28
0
void CalcFullViewWindowSize( LPRECT lpWindowRect, LPRECT lpFileRect,
                              LFIXED FileRate, int npix, int nlin, int x,
                              int y, BOOL fHasRulers, BOOL fClipToImage )
/************************************************************************/
{
int dx, dy, sx, sy, rs, iImageWidth, iImageHeight, iWidth, iHeight;
LFIXED DispRate;
int minsize;

// normal window - to goal is to size the window to fit the view
// If FileRate == 0 or 1, then we make the window as big as possible
// for the FileRect provided.  If FileRate != 0, then we make the
// the window as big as possible to fit the image at that FileRate.
// If the fClipToImage flag and FileRate == 0, then we do not let
// the FileRate go over 100%.  This is used for a caller who wants
// to display the image pixel for pixel, if possible.
if (x < 0 || y < 0)
	GetDocumentPosition(&x, &y);

dx = 2 * GetSystemMetrics(SM_CXFRAME);
dy = GetSystemMetrics(SM_CYCAPTION) + (2*GetSystemMetrics(SM_CYFRAME)) - 1;

// get size of scrollbars and rulers for use later
GetScrollBarSize(&sx, &sy);
rs = GetRulerSize();

// determine maximum area for window to occupy
if (IsIconic(PictPubApp.Get_hWndAstral()))
    *lpWindowRect = rClient;
else
    GetClientRect(PictPubApp.Get_hClientAstral(), lpWindowRect);
lpWindowRect->top = y;
lpWindowRect->left = x;
lpWindowRect->right -= dx;
lpWindowRect->bottom -= (dy + GetSystemMetrics(SM_CYFRAME));

// start with this maximum Client Area size
minsize = MIN_WINDOW_SIZE+rs;
iWidth = RectWidth(lpWindowRect);
if ( iWidth < minsize )
    iWidth = minsize;
iHeight = RectHeight(lpWindowRect);
if ( iHeight < minsize )
    iHeight = minsize;

// If we already have a FileRate, calculate new size of window
// based on the image size
if (FileRate > TINYRATE)
    {
    // calculate size of area for total image at this
    // FileRate
    DispRate = FGET(FUNITY, FileRate);
    iImageWidth = FMUL(npix, DispRate);
    iImageHeight = FMUL(nlin, DispRate);

    // add in additional space for rulers if necessary
    if (fHasRulers)
        {
        iImageWidth += rs;
        iImageHeight += rs;
        }
    if (iImageWidth > iWidth && iImageHeight < iHeight)
        iImageHeight += sy;
    if (iImageHeight > iHeight && iImageWidth < iWidth)
        iImageWidth += sx;

    // see if we don't need the total width
    // otherwise, use the maximum
    if (iImageWidth < iWidth)
        iWidth = iImageWidth;
    // see if we don't need the total height
    // otherwise, use the maximum
    if (iImageHeight < iHeight)
        iHeight = iImageHeight;
    }
// if we have no FileRate, then somebody wants a specific
// FileRect, figure out how big the window needs to be and
// whether we need rulers
else
    {
    // get width and height of area to be displayed
    iImageWidth = RectWidth(lpFileRect);
    iImageHeight = RectHeight(lpFileRect);

    // reduce the maximum area if we have rulers
    if (fHasRulers)
        {
        iWidth -= rs;
        iHeight -= rs;
        }

    // reduce the maximum area if we need scrollbars
    if (lpFileRect->left != 0 ||
        lpFileRect->right != npix-1 ||
        lpFileRect->top != 0 ||
        lpFileRect->bottom != nlin-1)
        {
        iWidth -= sx;
        iHeight -= sy;
        }

    // scale maximum client area size (not including rulers and
    // scrollbars) to fit aspect ratio of FileRect
    DispRate = ScaleToFit(&iWidth, &iHeight, iImageWidth, iImageHeight);

    // if caller wants to clip to hires to achieve 100% view,
    // clip.  But only if hires is smaller
    if (iImageWidth <= iWidth && iImageHeight <= iHeight && fClipToImage)
        {
        iWidth = iImageWidth;
        iHeight = iImageHeight;
        }

    // add ruler size back into client area
    if (fHasRulers)
        {
        iWidth += rs;
        iHeight += rs;
        }

    // add scrollbar size back into client area
    if (lpFileRect->left != 0 ||
        lpFileRect->right != npix-1 ||
        lpFileRect->top != 0 ||
        lpFileRect->bottom != nlin-1)
        {
        iWidth += sx;
        iHeight += sy;
        }
    }
// Calculate new window size based on iWidth and iHeight */
lpWindowRect->right = lpWindowRect->left + iWidth + dx - 1;
lpWindowRect->bottom = lpWindowRect->top + iHeight + dy - 1;
}
Exemplo n.º 29
0
static int ComputeZoom( HWND hWnd, int x, int y, int value,
                        BOOL fIncremental, LFIXED *lfFileRate,
                        int *Percentage )
/************************************************************************/
{
LFIXED DispRate;
int OldPercentage, iImageWidth, iImageHeight;
LPIMAGE lpImage;
LPDISPLAY lpDisplay;

HWND hMDIWindow = hWnd;
CWnd *pWnd = CWnd::FromHandle(hMDIWindow);
if (pWnd->IsKindOf(RUNTIME_CLASS(CServerView)))        
	hMDIWindow = pWnd->GetParentFrame()->GetSafeHwnd();

if (IsIconic(hMDIWindow))
    return(FALSE);

lpImage = GetImagePtr(hWnd);
lpDisplay = GetDisplayPtr(hWnd);

// Compute the viewing percentage, if necessary
if ( !(*Percentage = lpDisplay->ViewPercentage) )
    *Percentage = FMUL( 100, lpDisplay->DispRate );

// Compute the NEW viewing percentage, and DispRate
if ( fIncremental )
    {
    if (value < 0)
        {
        if (*Percentage > 100)
            {
            if (*Percentage % 100 != 0)
                *Percentage -= *Percentage % 100;
            else
                *Percentage -= 100;
            }
        else
        if (*Percentage <= 1)
            *Percentage = 0;
        else
            {
            OldPercentage = *Percentage;
            *Percentage = 100;
            while (*Percentage >= OldPercentage)
                *Percentage = (*Percentage+1)/2;
            }
        }
    else
    if (value > 0)
        {
        if (*Percentage > 32600)
            *Percentage = 0;
        else
        if (*Percentage >= 50)
            *Percentage = ((*Percentage+100)/100) * 100;
        else
        if (*Percentage)
            {
            OldPercentage = (*Percentage * 2) + 1;
            *Percentage = 100;
            while (*Percentage > OldPercentage)
                *Percentage = (*Percentage+1)/2;
            }
        else
            *Percentage = 1;
        }
    }
else
if (value > 0 && value < 32700)
    *Percentage  = value;
else
    *Percentage = 0;

// do we have a valid zoom percentage?
if (!*Percentage)
    return(FALSE);

// can we mathematically support this percentage?
DispRate = FGET( *Percentage, 100 );  /* DispRate */
*lfFileRate = FGET( 100, *Percentage );  /* FileRate */
if (!CanZoom(hWnd, *lfFileRate, &lpDisplay->FileRect,
        &lpDisplay->DispRect))
    {
    return(FALSE);
    }

// is our display surface too small?
iImageWidth = FMUL(lpImage->npix, DispRate);
iImageHeight = FMUL(lpImage->nlin, DispRate);
if (iImageHeight < 1 || iImageWidth < 1)
    {
    return(FALSE);
    }
return(TRUE);
}
Exemplo n.º 30
0
/************************************************************************
	UnhookZoom
		Unhooks the zoom window from the specified window.
		if this was its owner then zoom window destroys itself..
************************************************************************/

void UnhookZoom(HWND hWnd)
{
HWND hOwner, hWndMe;

if (!hZoomWindow)
	return;
hOwner = GetZoomOwner(hZoomWindow);
if (hOwner != hWnd || !hOwner)
	return;
hWndMe = hZoomWindow;
DestroyWindow(hWndMe);		// will set hZoomWindow = NULL
hZoomWindow = NULL;
}

//************************************************************************
//  ZoomSizeToDef
//		  Computes and sets size and position on the screen
//				for the new zoom window	according to the defaults
//***********************************************************************/
void ZoomSizeToDef()
{
	LPIMAGE lpMyImage;
	RECT rOwner, rArea, rParent;
	HWND hWndOwner,hParent;
	int x,y,height, width;
	int borderW, borderH;
	STRING szString;

	if (!hZoomWindow)
		return;
    lpMyImage = (LPIMAGE)GetImagePtr (hZoomWindow );
	hWndOwner = GetZoomOwner(hZoomWindow);
	hParent = PictPubApp.Get_hWndAstral();
	if (!hWndOwner || !hParent)
		return;
	if (hZoomWindow && lpMyImage )
	{
		x = View.rZoomRect.left;
		y = View.rZoomRect.top;
		width  = View.rZoomRect.right - View.rZoomRect.left;
		height = View.rZoomRect.bottom - View.rZoomRect.top;
		if (height == 0 || width == 0)
		{ // no previous values
			// use saved values if possible
			GetDefaultString( _T("sizeZoom"), _T("0,0"), szString, sizeof(STRING) );
			AsciiToInt2( szString, &width, &height);
			if (width+height != 0)
			{
				MoveWindow (hZoomWindow,x,y,width, height, FALSE);
				if (RestorePopup( hZoomWindow, _T("xyZoom"), NULL ))
				{
					// Restore popup will change View.rZoomRect
					x = View.rZoomRect.left;
					y = View.rZoomRect.top;
					MoveWindow (hZoomWindow,x,y,width, height, FALSE);
					return;
				}
			}
			// saved values failed, now use defaults
			GetWindowRect(hZoomWindow, &rArea);
			borderW = rArea.right - rArea.left;
			borderH = rArea.bottom - rArea.top;
			GetClientRect(hZoomWindow, &rArea);
			borderW -= rArea.right - rArea.left;
			borderH -= rArea.bottom - rArea.top;
			GetClientRect(hWndOwner, &rOwner);
			GetClientRect(hParent, &rParent);
			height = FMUL(RectHeight(&rOwner),
				View.ZoomDefaultSize)+borderH;
			width = FMUL(RectWidth(&rOwner),
				View.ZoomDefaultSize)+borderW;
			x = rParent.right-width;
			y = rParent.top + borderH;
			if (IsIconic(hWndOwner))
			{
				height = (rOwner.bottom - rOwner.top)+borderH;
				width = (rOwner.right - rOwner.left)+borderW;
			}
		}
		MoveWindow (hZoomWindow,x,y,width, height, FALSE);
 	}
}