/** * 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; }
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; }
static void Loc_cbInfo( LocState *pts ) { if( pts->theInfo.status == AEEGPS_ERR_NO_ERR || (pts->theInfo.status == AEEGPS_ERR_INFO_UNAVAIL && pts->theInfo.fValid) ) { #if MIN_BREW_VERSION(2,1) pts->pResp->lat = WGS84_TO_DEGREES( pts->theInfo.dwLat ); #ifdef AEE_SIMULATOR //FOR TEST pts->pResp->lon = -WGS84_TO_DEGREES( pts->theInfo.dwLon ); #else pts->pResp->lon = WGS84_TO_DEGREES( pts->theInfo.dwLon ); #endif #else double wgsFactor; wgsFactor = FASSIGN_STR("186413.5111"); pts->pResp->lat = FASSIGN_INT(pts->theInfo.dwLat); pts->pResp->lat = FDIV(pts->pResp->lat, wgsFactor); pts->pResp->lon = FASSIGN_INT(pts->theInfo.dwLon); pts->pResp->lon = FDIV(pts->pResp->lon, wgsFactor); #endif /* MIN_BREW_VERSION 2.1 */ pts->pResp->height = pts->theInfo.wAltitude - 500; pts->pResp->velocityHor = FMUL( pts->theInfo.wVelocityHor,0.25); //当前夹角 if (FCMP_G(FABS(pts->lastCoordinate.lat), 0)) { pts->pResp->heading = Loc_Calc_Azimuth(pts->lastCoordinate.lat, pts->lastCoordinate.lon, pts->pResp->lat, pts->pResp->lon); } else { pts->pResp->heading = 0; } //For Test Hack #ifdef AEE_SIMULATOR pts->pResp->lat = 38.0422378880; pts->pResp->lon = 114.4925141047; #endif if (pts->pResp->bSetDestPos) { //计算距离和方位角 pts->pResp->distance = Loc_Calc_Distance(pts->pResp->lat, pts->pResp->lon, pts->pResp->destPos.lat, pts->pResp->destPos.lon); pts->pResp->destHeading = Loc_Calc_Azimuth(pts->pResp->lat, pts->pResp->lon, pts->pResp->destPos.lat, pts->pResp->destPos.lon); } //记录历史定位信息 pts->lastCoordinate.lat = pts->pResp->lat; pts->lastCoordinate.lon = pts->pResp->lon; pts->pResp->dwFixNum++; pts->pResp->nErr = SUCCESS; Loc_Notify( pts ); if( FALSE == pts->bSetForCancellation ) { ISHELL_SetTimerEx( pts->pShell, pts->nLocInterval * 1000, &pts->cbIntervalTimer ); } else { Loc_Stop( pts ); } } }
/** * Parse a colour specifier * * \param c Parsing context * \param vector Vector of tokens to process * \param ctx Pointer to vector iteration context * \param value Pointer to location to receive value * \param result Pointer to location to receive result (AARRGGBB) * \return CSS_OK on success, * CSS_INVALID if the input is invalid * * Post condition: \a *ctx is updated with the next token to process * If the input is invalid, then \a *ctx remains unchanged. */ css_error css__parse_colour_specifier(css_language *c, const parserutils_vector *vector, int *ctx, uint16_t *value, uint32_t *result) { int orig_ctx = *ctx; const css_token *token; bool match; css_error error; consumeWhitespace(vector, ctx); /* IDENT(<colour name>) | * HASH(rgb | rrggbb) | * FUNCTION(rgb) [ [ NUMBER | PERCENTAGE ] ',' ] {3} ')' * FUNCTION(rgba) [ [ NUMBER | PERCENTAGE ] ',' ] {4} ')' * FUNCTION(hsl) ANGLE ',' PERCENTAGE ',' PERCENTAGE ')' * FUNCTION(hsla) ANGLE ',' PERCENTAGE ',' PERCENTAGE ',' NUMBER ')' * * For quirks, NUMBER | DIMENSION | IDENT, too * I.E. "123456" -> NUMBER, "1234f0" -> DIMENSION, "f00000" -> IDENT */ token = parserutils_vector_iterate(vector, ctx); if (token == NULL || (token->type != CSS_TOKEN_IDENT && token->type != CSS_TOKEN_HASH && token->type != CSS_TOKEN_FUNCTION)) { if (c->sheet->quirks_allowed == false || token == NULL || (token->type != CSS_TOKEN_NUMBER && token->type != CSS_TOKEN_DIMENSION)) goto invalid; } if (token->type == CSS_TOKEN_IDENT) { if ((lwc_string_caseless_isequal( token->idata, c->strings[TRANSPARENT], &match) == lwc_error_ok && match)) { *value = COLOR_TRANSPARENT; *result = 0; /* black transparent */ return CSS_OK; } else if ((lwc_string_caseless_isequal( token->idata, c->strings[CURRENTCOLOR], &match) == lwc_error_ok && match)) { *value = COLOR_CURRENT_COLOR; *result = 0; return CSS_OK; } error = css__parse_named_colour(c, token->idata, result); if (error != CSS_OK && c->sheet->quirks_allowed) { error = css__parse_hash_colour(token->idata, result); if (error == CSS_OK) c->sheet->quirks_used = true; } if (error != CSS_OK) goto invalid; } else if (token->type == CSS_TOKEN_HASH) { error = css__parse_hash_colour(token->idata, result); if (error != CSS_OK) goto invalid; } else if (c->sheet->quirks_allowed && token->type == CSS_TOKEN_NUMBER) { error = css__parse_hash_colour(token->idata, result); if (error == CSS_OK) c->sheet->quirks_used = true; else goto invalid; } else if (c->sheet->quirks_allowed && token->type == CSS_TOKEN_DIMENSION) { error = css__parse_hash_colour(token->idata, result); if (error == CSS_OK) c->sheet->quirks_used = true; else goto invalid; } else if (token->type == CSS_TOKEN_FUNCTION) { uint8_t r = 0, g = 0, b = 0, a = 0xff; int colour_channels = 0; if ((lwc_string_caseless_isequal( token->idata, c->strings[RGB], &match) == lwc_error_ok && match)) { colour_channels = 3; } else if ((lwc_string_caseless_isequal( token->idata, c->strings[RGBA], &match) == lwc_error_ok && match)) { colour_channels = 4; } if ((lwc_string_caseless_isequal( token->idata, c->strings[HSL], &match) == lwc_error_ok && match)) { colour_channels = 5; } else if ((lwc_string_caseless_isequal( token->idata, c->strings[HSLA], &match) == lwc_error_ok && match)) { colour_channels = 6; } if (colour_channels == 3 || colour_channels == 4) { int i; css_token_type valid = CSS_TOKEN_NUMBER; uint8_t *components[4] = { &r, &g, &b, &a }; for (i = 0; i < colour_channels; i++) { uint8_t *component; css_fixed num; size_t consumed = 0; int32_t intval; bool int_only; component = components[i]; consumeWhitespace(vector, ctx); token = parserutils_vector_peek(vector, *ctx); if (token == NULL || (token->type != CSS_TOKEN_NUMBER && token->type != CSS_TOKEN_PERCENTAGE)) goto invalid; if (i == 0) valid = token->type; else if (i < 3 && token->type != valid) goto invalid; /* The alpha channel may be a float */ if (i < 3) int_only = (valid == CSS_TOKEN_NUMBER); else int_only = false; num = css__number_from_lwc_string(token->idata, int_only, &consumed); if (consumed != lwc_string_length(token->idata)) goto invalid; if (valid == CSS_TOKEN_NUMBER) { if (i == 3) { /* alpha channel */ intval = FIXTOINT( FMUL(num, F_255)); } else { /* colour channels */ intval = FIXTOINT(num); } } else { intval = FIXTOINT( FDIV(FMUL(num, F_255), F_100)); } if (intval > 255) *component = 255; else if (intval < 0) *component = 0; else *component = intval; parserutils_vector_iterate(vector, ctx); consumeWhitespace(vector, ctx); token = parserutils_vector_peek(vector, *ctx); if (token == NULL) goto invalid; if (i != (colour_channels - 1) && tokenIsChar(token, ',')) { parserutils_vector_iterate(vector, ctx); } else if (i == (colour_channels - 1) && tokenIsChar(token, ')')) { parserutils_vector_iterate(vector, ctx); } else { goto invalid; } } } else if (colour_channels == 5 || colour_channels == 6) { /* hue - saturation - lightness */ size_t consumed = 0; css_fixed hue, sat, lit; int32_t alpha = 255; /* hue is a number without a unit representing an * angle (0-360) degrees */ consumeWhitespace(vector, ctx); token = parserutils_vector_iterate(vector, ctx); if ((token == NULL) || (token->type != CSS_TOKEN_NUMBER)) goto invalid; hue = css__number_from_lwc_string(token->idata, false, &consumed); if (consumed != lwc_string_length(token->idata)) goto invalid; /* failed to consume the whole string as a number */ /* Normalise hue to the range [0, 360) */ while (hue < 0) hue += F_360; while (hue >= F_360) hue -= F_360; consumeWhitespace(vector, ctx); token = parserutils_vector_iterate(vector, ctx); if (!tokenIsChar(token, ',')) goto invalid; /* saturation */ consumeWhitespace(vector, ctx); token = parserutils_vector_iterate(vector, ctx); if ((token == NULL) || (token->type != CSS_TOKEN_PERCENTAGE)) goto invalid; sat = css__number_from_lwc_string(token->idata, false, &consumed); if (consumed != lwc_string_length(token->idata)) goto invalid; /* failed to consume the whole string as a number */ /* Normalise saturation to the range [0, 100] */ if (sat < INTTOFIX(0)) sat = INTTOFIX(0); else if (sat > INTTOFIX(100)) sat = INTTOFIX(100); consumeWhitespace(vector, ctx); token = parserutils_vector_iterate(vector, ctx); if (!tokenIsChar(token, ',')) goto invalid; /* lightness */ consumeWhitespace(vector, ctx); token = parserutils_vector_iterate(vector, ctx); if ((token == NULL) || (token->type != CSS_TOKEN_PERCENTAGE)) goto invalid; lit = css__number_from_lwc_string(token->idata, false, &consumed); if (consumed != lwc_string_length(token->idata)) goto invalid; /* failed to consume the whole string as a number */ /* Normalise lightness to the range [0, 100] */ if (lit < INTTOFIX(0)) lit = INTTOFIX(0); else if (lit > INTTOFIX(100)) lit = INTTOFIX(100); consumeWhitespace(vector, ctx); token = parserutils_vector_iterate(vector, ctx); if (colour_channels == 6) { /* alpha */ if (!tokenIsChar(token, ',')) goto invalid; consumeWhitespace(vector, ctx); token = parserutils_vector_iterate(vector, ctx); if ((token == NULL) || (token->type != CSS_TOKEN_NUMBER)) goto invalid; alpha = css__number_from_lwc_string(token->idata, false, &consumed); if (consumed != lwc_string_length(token->idata)) goto invalid; /* failed to consume the whole string as a number */ alpha = FIXTOINT(FMUL(alpha, F_255)); consumeWhitespace(vector, ctx); token = parserutils_vector_iterate(vector, ctx); } if (!tokenIsChar(token, ')')) goto invalid; /* have a valid HSV entry, convert to RGB */ HSL_to_RGB(hue, sat, lit, &r, &g, &b); /* apply alpha */ if (alpha > 255) a = 255; else if (alpha < 0) a = 0; else a = alpha; } else { goto invalid; } *result = (a << 24) | (r << 16) | (g << 8) | b; } *value = COLOR_SET; return CSS_OK; invalid: *ctx = orig_ctx; return CSS_INVALID; }
/** * Convert Hue Saturation Lightness value to RGB. * * \param hue Hue in degrees 0..360 * \param sat Saturation value in percent 0..100 * \param lit Lightness value in percent 0..100 * \param r red component * \param g green component * \param b blue component */ static void HSL_to_RGB(css_fixed hue, css_fixed sat, css_fixed lit, uint8_t *r, uint8_t *g, uint8_t *b) { css_fixed min_rgb, max_rgb, chroma; css_fixed relative_hue, scaled_hue, mid1, mid2; int sextant; #define ORGB(R, G, B) \ *r = FIXTOINT(FDIV(FMUL((R), F_255), F_100)); \ *g = FIXTOINT(FDIV(FMUL((G), F_255), F_100)); \ *b = FIXTOINT(FDIV(FMUL((B), F_255), F_100)) /* If saturation is zero there is no hue and r = g = b = lit */ if (sat == INTTOFIX(0)) { ORGB(lit, lit, lit); return; } /* Compute max(r,g,b) */ if (lit <= INTTOFIX(50)) { max_rgb = FDIV(FMUL(lit, FADD(sat, F_100)), F_100); } else { max_rgb = FDIV(FSUB(FMUL(FADD(lit, sat), F_100), FMUL(lit, sat)), F_100); } /* Compute min(r,g,b) */ min_rgb = FSUB(FMUL(lit, INTTOFIX(2)), max_rgb); /* We know that the value of at least one of the components is * max(r,g,b) and that the value of at least one of the other * components is min(r,g,b). * * We can determine which components have these values by * considering which the sextant of the hexcone the hue lies * in: * * Sextant: max(r,g,b): min(r,g,b): * * 0 r b * 1 g b * 2 g r * 3 b r * 4 b g * 5 r g * * Thus, we need only compute the value of the third component */ /* Chroma is the difference between min and max */ chroma = FSUB(max_rgb, min_rgb); /* Compute which sextant the hue lies in (truncates result) */ hue = FDIV(FMUL(hue, INTTOFIX(6)), F_360); sextant = FIXTOINT(hue); /* Compute offset of hue from start of sextant */ relative_hue = FSUB(hue, INTTOFIX(sextant)); /* Scale offset by chroma */ scaled_hue = FMUL(relative_hue, chroma); /* Compute potential values of the third colour component */ mid1 = FADD(min_rgb, scaled_hue); mid2 = FSUB(max_rgb, scaled_hue); /* Populate result */ switch (sextant) { case 0: ORGB(max_rgb, mid1, min_rgb); break; case 1: ORGB(mid2, max_rgb, min_rgb); break; case 2: ORGB(min_rgb, max_rgb, mid1); break; case 3: ORGB(min_rgb, mid2, max_rgb); break; case 4: ORGB(mid1, min_rgb, max_rgb); break; case 5: ORGB(max_rgb, min_rgb, mid2); break; } #undef ORGB }
/*=========================================================================== ===========================================================================*/ static void SamplePosDet_GetGPSInfo_Paint( CSamplePosDet *pMe, GetGPSInfo_PaintRegions rgn ) { struct _GetGPSInfo *pGetGPSInfo = SamplePosDet_GetScreenData( pMe ); if( rgn == GETGPSINFO_PAINT_ALL ) { IDISPLAY_ClearScreen( pMe->theApp.m_pIDisplay ); SamplePosDet_Printf( pMe, 0, 3, AEE_FONT_BOLD, IDF_ALIGN_LEFT, "GetGPSInfo" ); if( pGetGPSInfo->wMainMenuEntry == MAINMENU_ITEM_ONE_SHOT ) { SamplePosDet_Printf( pMe, 0, 3, AEE_FONT_BOLD, IDF_ALIGN_RIGHT, "One Shot" ); } else if( pGetGPSInfo->wMainMenuEntry == MAINMENU_ITEM_TRACK_LOCAL ) { SamplePosDet_Printf( pMe, 0, 3, AEE_FONT_BOLD, IDF_ALIGN_RIGHT, "Track L" ); } else if( pGetGPSInfo->wMainMenuEntry == MAINMENU_ITEM_TRACK_NETWORK ) { SamplePosDet_Printf( pMe, 0, 3, AEE_FONT_BOLD, IDF_ALIGN_RIGHT, "Track N" ); } else if( pGetGPSInfo->wMainMenuEntry == MAINMENU_ITEM_TRACK_AUTO ) { SamplePosDet_Printf( pMe, 0, 3, AEE_FONT_BOLD, IDF_ALIGN_RIGHT, "Track A" ); } } if( rgn == GETGPSINFO_PAINT_FIXCOUNT || rgn == GETGPSINFO_PAINT_ALL ) { SamplePosDet_Printf( pMe, 1, 4, AEE_FONT_NORMAL, IDF_ALIGN_LEFT, "Failed : %d", pGetGPSInfo->dwFail+pGetGPSInfo->dwTimeout ); SamplePosDet_Printf( pMe, 1, 4, AEE_FONT_NORMAL, IDF_ALIGN_RIGHT, "Timeout : %d", pGetGPSInfo->dwTimeout ); } if( rgn == GETGPSINFO_PAINT_FIXDATA || rgn == GETGPSINFO_PAINT_ALL ) { #define MAXTEXTLEN 22 AECHAR wcText[MAXTEXTLEN]; char latlonStr[MAXTEXTLEN]; SamplePosDet_Printf( pMe, 2, 4, AEE_FONT_NORMAL, IDF_ALIGN_LEFT, "Fixes : %d", pGetGPSInfo->dwFixNumber ); FLOATTOWSTR( pGetGPSInfo->theInfo.lat, wcText, MAXTEXTLEN * sizeof(AECHAR) ); WSTR_TO_STR( wcText, latlonStr, MAXTEXTLEN ); SamplePosDet_Printf( pMe, 3, 4, AEE_FONT_BOLD, IDF_ALIGN_CENTER|IDF_RECT_FILL, "%s d", latlonStr ); FLOATTOWSTR( pGetGPSInfo->theInfo.lon, wcText, MAXTEXTLEN * sizeof(AECHAR) ); WSTR_TO_STR( wcText, latlonStr, MAXTEXTLEN ); SamplePosDet_Printf( pMe, 4, 4, AEE_FONT_BOLD, IDF_ALIGN_CENTER|IDF_RECT_FILL, "%s d", latlonStr ); SamplePosDet_Printf( pMe, 5, 4, AEE_FONT_BOLD, IDF_ALIGN_RIGHT|IDF_RECT_FILL, "%d m", pGetGPSInfo->theInfo.height ); { double fv; fv = FASSIGN_INT( pGetGPSInfo->dwFixDuration ); if( pGetGPSInfo->dwFixNumber ) { fv = FDIV(fv, pGetGPSInfo->dwFixNumber); } FLOATTOWSTR( fv, wcText, MAXTEXTLEN * sizeof(AECHAR) ); WSTR_TO_STR( wcText, latlonStr, MAXTEXTLEN ); SamplePosDet_Printf( pMe, 6, 4, AEE_FONT_BOLD, IDF_ALIGN_RIGHT|IDF_RECT_FILL, "Avg %ss", latlonStr ); } } if( rgn == GETGPSINFO_PAINT_ERROR ) { SamplePosDet_Printf( pMe, 7, 4, AEE_FONT_BOLD, IDF_ALIGN_BOTTOM|IDF_ALIGN_CENTER|IDF_TEXT_INVERTED, "ABORTED 0x%x", pGetGPSInfo->theInfo.nErr ); } if( rgn == GETGPSINFO_PAINT_FIXANIM || rgn == GETGPSINFO_PAINT_ALL ) { SamplePosDet_Printf( pMe, 7, 4, AEE_FONT_NORMAL, IDF_ALIGN_BOTTOM|IDF_ALIGN_CENTER|IDF_RECT_FILL, ".....%d.....", pGetGPSInfo->wProgress ); } //if (FABS(pGetGPSInfo->theInfo.lat) > 0) { Coordinate c1, c2; double dis = 0; char szDis[64]; AECHAR wcharbuf[32]; //shanghai 31.1774276, 121.5272106 c1.lat = 31.1774276; c1.lon = 121.5272106; //beijing 39.911954, 116.377817 c2.lat = 39.911954; c2.lon = 116.377817; //shenzhen 22.543847, 113.912316 //c1.lat = 22.543847; //c1.lon = 113.912316; c1.lat = pGetGPSInfo->theInfo.lat; c1.lon = pGetGPSInfo->theInfo.lon; dis = Track_Calc_Distance(c1.lat, c1.lon, c2.lat, c2.lon); MEMSET(szDis,0,sizeof(szDis)); FLOATTOWSTR(dis, wcharbuf, 32); WSTRTOSTR(wcharbuf,szDis, 64); DBGPRINTF("Track_cbOrientInfo dis:%s", szDis); SamplePosDet_Printf( pMe, 7, 4, AEE_FONT_BOLD, IDF_ALIGN_LEFT|IDF_RECT_FILL, "%s m", szDis ); } { uint16 d1 = 0; uint8 d2 = 0; d1 = ((uint16)(pGetGPSInfo->theInfo.wAzimuth & (~0x3f)))>>6; d2 = (uint8)(pGetGPSInfo->theInfo.wAzimuth & 0x3f); SamplePosDet_Printf( pMe, 8, 4, AEE_FONT_BOLD, IDF_ALIGN_LEFT|IDF_RECT_FILL, "Head %d.%d", d1, d2 ); SamplePosDet_Printf( pMe, 9, 4, AEE_FONT_BOLD, IDF_ALIGN_LEFT|IDF_RECT_FILL, "Heading %d", pGetGPSInfo->theInfo.heading); } }
/** * Convert a CSS length to pixels. * * \param length Length to convert * \param unit Corresponding unit * \param style Computed style applying to length. May be NULL if unit is * neither em nor ex * \return length in pixels */ css_fixed nscss_len2px(css_fixed length, css_unit unit, const css_computed_style *style) { /* We assume the screen and ay other output has the same dpi */ css_fixed px_per_unit; assert(style != NULL || (unit != CSS_UNIT_EM && unit != CSS_UNIT_EX)); switch (unit) { case CSS_UNIT_EM: case CSS_UNIT_EX: { css_fixed font_size = 0; css_unit font_unit = CSS_UNIT_PT; css_computed_font_size(style, &font_size, &font_unit); /* Convert to points */ font_size = nscss_len2pt(font_size, font_unit); /* Clamp to configured minimum */ if (font_size < FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10)) { font_size = FDIV(INTTOFIX(nsoption_int(font_min_size)), F_10); } /* Convert to pixels (manually, to maximise precision) * 1in = 72pt => 1pt = (DPI/72)px */ px_per_unit = FDIV(FMUL(font_size, nscss_screen_dpi), F_72); /* Scale ex units: we use a fixed ratio of 1ex = 0.6em */ if (unit == CSS_UNIT_EX) px_per_unit = FMUL(px_per_unit, FLTTOFIX(0.6)); } break; case CSS_UNIT_PX: px_per_unit = F_1; break; /* 1in = DPIpx */ case CSS_UNIT_IN: px_per_unit = nscss_screen_dpi; break; /* 1in = 2.54cm => 1cm = (DPI/2.54)px */ case CSS_UNIT_CM: px_per_unit = FDIV(nscss_screen_dpi, FLTTOFIX(2.54)); break; /* 1in = 25.4mm => 1mm = (DPI/25.4)px */ case CSS_UNIT_MM: px_per_unit = FDIV(nscss_screen_dpi, FLTTOFIX(25.4)); break; /* 1in = 72pt => 1pt = (DPI/72)px */ case CSS_UNIT_PT: px_per_unit = FDIV(nscss_screen_dpi, F_72); break; /* 1pc = 12pt => 1in = 6pc => 1pc = (DPI/6)px */ case CSS_UNIT_PC: px_per_unit = FDIV(nscss_screen_dpi, INTTOFIX(6)); break; default: px_per_unit = 0; break; } /* Ensure we round px_per_unit to the nearest whole number of pixels: * the use of FIXTOINT() below will truncate. */ px_per_unit += F_0_5; /* Calculate total number of pixels */ return FMUL(length, TRUNCATEFIX(px_per_unit)); }
/** * Compute the absolute values of a style * * \param parent Parent style, or NULL for tree root * \param style Computed style to process * \param compute_font_size Callback to calculate an absolute font-size * \param pw Private word for callback * \return CSS_OK on success. */ css_error compute_absolute_values(const css_computed_style *parent, css_computed_style *style, css_error (*compute_font_size)(void *pw, const css_hint *parent, css_hint *size), void *pw) { css_hint psize, size, ex_size; css_error error; /* Ensure font-size is absolute */ if (parent != NULL) { psize.status = get_font_size(parent, &psize.data.length.value, &psize.data.length.unit); } size.status = get_font_size(style, &size.data.length.value, &size.data.length.unit); error = compute_font_size(pw, parent != NULL ? &psize : NULL, &size); if (error != CSS_OK) return error; error = set_font_size(style, size.status, size.data.length.value, size.data.length.unit); if (error != CSS_OK) return error; /* Compute the size of an ex unit */ ex_size.status = CSS_FONT_SIZE_DIMENSION; ex_size.data.length.value = INTTOFIX(1); ex_size.data.length.unit = CSS_UNIT_EX; error = compute_font_size(pw, &size, &ex_size); if (error != CSS_OK) return error; /* Convert ex size into ems */ if (size.data.length.value != 0) ex_size.data.length.value = FDIV(ex_size.data.length.value, size.data.length.value); else ex_size.data.length.value = 0; ex_size.data.length.unit = CSS_UNIT_EM; /* Fix up background-position */ error = compute_absolute_length_pair(style, &ex_size.data.length, get_background_position, set_background_position); if (error != CSS_OK) return error; /* Fix up border-{top,right,bottom,left}-color */ error = compute_border_colors(style); if (error != CSS_OK) return error; /* Fix up border-{top,right,bottom,left}-width */ error = compute_absolute_border_width(style, &ex_size.data.length); if (error != CSS_OK) return error; /* Fix up sides */ error = compute_absolute_sides(style, &ex_size.data.length); if (error != CSS_OK) return error; /* Fix up height */ error = compute_absolute_length_auto(style, &ex_size.data.length, get_height, set_height); if (error != CSS_OK) return error; /* Fix up line-height (must be before vertical-align) */ error = compute_absolute_line_height(style, &ex_size.data.length); if (error != CSS_OK) return error; /* Fix up margins */ error = compute_absolute_margins(style, &ex_size.data.length); if (error != CSS_OK) return error; /* Fix up max-height */ error = compute_absolute_length_none(style, &ex_size.data.length, get_max_height, set_max_height); if (error != CSS_OK) return error; /* Fix up max-width */ error = compute_absolute_length_none(style, &ex_size.data.length, get_max_width, set_max_width); if (error != CSS_OK) return error; /* Fix up min-height */ error = compute_absolute_length(style, &ex_size.data.length, get_min_height, set_min_height); if (error != CSS_OK) return error; /* Fix up min-width */ error = compute_absolute_length(style, &ex_size.data.length, get_min_width, set_min_width); if (error != CSS_OK) return error; /* Fix up padding */ error = compute_absolute_padding(style, &ex_size.data.length); if (error != CSS_OK) return error; /* Fix up text-indent */ error = compute_absolute_length(style, &ex_size.data.length, get_text_indent, set_text_indent); if (error != CSS_OK) return error; /* Fix up vertical-align */ error = compute_absolute_vertical_align(style, &ex_size.data.length); if (error != CSS_OK) return error; /* Fix up width */ error = compute_absolute_length_auto(style, &ex_size.data.length, get_width, set_width); if (error != CSS_OK) return error; /* Uncommon properties */ if (style->uncommon != NULL) { /* Fix up border-spacing */ error = compute_absolute_length_pair(style, &ex_size.data.length, get_border_spacing, set_border_spacing); if (error != CSS_OK) return error; /* Fix up clip */ error = compute_absolute_clip(style, &ex_size.data.length); if (error != CSS_OK) return error; /* Fix up letter-spacing */ error = compute_absolute_length_normal(style, &ex_size.data.length, get_letter_spacing, set_letter_spacing); if (error != CSS_OK) return error; /* Fix up outline-width */ error = compute_absolute_border_side_width(style, &ex_size.data.length, get_outline_width, set_outline_width); if (error != CSS_OK) return error; /* Fix up word spacing */ error = compute_absolute_length_normal(style, &ex_size.data.length, get_word_spacing, set_word_spacing); if (error != CSS_OK) return error; } return CSS_OK; }
/** * Font size computation callback for libcss * * \param pw Computation context * \param parent Parent font size (absolute) * \param size Font size to compute * \return CSS_OK on success * * \post \a size will be an absolute font size */ css_error nscss_compute_font_size(void *pw, const css_hint *parent, css_hint *size) { /** * Table of font-size keyword scale factors * * These are multiplied by the configured default font size * to produce an absolute size for the relevant keyword */ static const css_fixed factors[] = { FLTTOFIX(0.5625), /* xx-small */ FLTTOFIX(0.6250), /* x-small */ FLTTOFIX(0.8125), /* small */ FLTTOFIX(1.0000), /* medium */ FLTTOFIX(1.1250), /* large */ FLTTOFIX(1.5000), /* x-large */ FLTTOFIX(2.0000) /* xx-large */ }; css_hint_length parent_size; /* Grab parent size, defaulting to medium if none */ if (parent == NULL) { parent_size.value = FDIV(FMUL(factors[CSS_FONT_SIZE_MEDIUM - 1], INTTOFIX(nsoption_int(font_size))), INTTOFIX(10)); parent_size.unit = CSS_UNIT_PT; } else { assert(parent->status == CSS_FONT_SIZE_DIMENSION); assert(parent->data.length.unit != CSS_UNIT_EM); assert(parent->data.length.unit != CSS_UNIT_EX); assert(parent->data.length.unit != CSS_UNIT_PCT); parent_size = parent->data.length; } assert(size->status != CSS_FONT_SIZE_INHERIT); if (size->status < CSS_FONT_SIZE_LARGER) { /* Keyword -- simple */ size->data.length.value = FDIV(FMUL(factors[size->status - 1], INTTOFIX(nsoption_int(font_size))), F_10); size->data.length.unit = CSS_UNIT_PT; } 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 = FDIV(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.unit == CSS_UNIT_CAP || size->data.length.unit == CSS_UNIT_CH || size->data.length.unit == CSS_UNIT_IC) { size->data.length.value = FMUL(size->data.length.value, parent_size.value); switch (size->data.length.unit) { case CSS_UNIT_EX: /* 1ex = 0.6em in NetSurf */ size->data.length.value = FMUL(size->data.length.value, FLTTOFIX(0.6)); break; case CSS_UNIT_CAP: /* Height of captals. 1cap = 0.9em in NetSurf. */ size->data.length.value = FMUL(size->data.length.value, FLTTOFIX(0.9)); break; case CSS_UNIT_CH: /* Width of '0'. 1ch = 0.4em in NetSurf. */ size->data.length.value = FMUL(size->data.length.value, FLTTOFIX(0.4)); break; case CSS_UNIT_IC: /* Width of U+6C43. 1ic = 1.1em in NetSurf. */ size->data.length.value = FMUL(size->data.length.value, FLTTOFIX(1.1)); break; default: /* No scaling required for EM. */ break; } 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), INTTOFIX(100)); size->data.length.unit = parent_size.unit; } else if (size->data.length.unit == CSS_UNIT_REM) { nscss_select_ctx *ctx = pw; if (parent == NULL) { size->data.length.value = parent_size.value; size->data.length.unit = parent_size.unit; } else { css_computed_font_size(ctx->root_style, &parent_size.value, &size->data.length.unit); size->data.length.value = FMUL( size->data.length.value, parent_size.value); } } else if (size->data.length.unit == CSS_UNIT_RLH) { /** TODO: Convert root element line-height to absolute value. */ size->data.length.value = FMUL(size->data.length.value, FDIV( INTTOFIX(nsoption_int(font_size)), INTTOFIX(10))); size->data.length.unit = CSS_UNIT_PT; } size->status = CSS_FONT_SIZE_DIMENSION; return CSS_OK; }
/* OnDraw() */ void CWallBrowserStretchView::OnDraw(CDC* pDC) { // documento CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument(); if(!pDoc) return; // nome file memset(m_szFileName,'\0',sizeof(m_szFileName)); strcpyn(m_szFileName,pDoc->GetFileName(),sizeof(m_szFileName)); if(m_szFileName[0]=='\0') return; // immagine CImage *pImage = pDoc->GetImage(); if(pImage && pImage->GetWidth() > 0 && pImage->GetHeight() > 0) m_ImageDraw.SetImage(pImage); else return; // immagine valida if(!pDoc->GetPictureFlag()) return; // dimensione corrente della vista GetClientRect(&m_rcClient); // adatta l'immagine alla dimensione corrente della vista double nRemains = 0.0; double nWidth = (double)pImage->GetWidth(); double nHeight = (double)pImage->GetHeight(); if(nHeight > (double)m_rcClient.bottom) { nRemains = FDIV(nHeight,(double)m_rcClient.bottom); if(nRemains > 0.0) { nHeight = FDIV(nHeight,nRemains); nWidth = FDIV(nWidth,nRemains); } } if(nWidth > (double)m_rcClient.right) { nRemains = FDIV(nWidth,(double)m_rcClient.right); if(nRemains > 0.0) { nHeight = FDIV(nHeight,nRemains); nWidth = FDIV(nWidth,nRemains); } } m_rcInvalid.SetRect(0,0,(int)nWidth,(int)nHeight); // nome del file if(m_pMainFrameStatusBar) { strcpyn(m_szStatus,pDoc->GetFileName(),sizeof(m_szStatus)); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_FILENAME_ID,m_szStatus); } double nFactor = 0.0; char szFactor[8] = {0}; if(m_nViewType==VIEWTYPE_SCROLL) { nFactor = GetZoomRatio(); if(nFactor >= 1.0) sprintf(szFactor,"%.2f:1",nFactor); else sprintf(szFactor,"1:%.2f",1/nFactor); } // fattore di zoom e % di visualizzazione dell'immagine nella vista int nRatio = (int)((nWidth * 100.0)/pImage->GetWidth()); if(m_pMainFrameStatusBar) { m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_ZOOM_ID,szFactor); if(m_nViewType==VIEWTYPE_STRETCH) _snprintf(m_szStatus,sizeof(m_szStatus)-1,"%d%% (stretch)",nRatio); else _snprintf(m_szStatus,sizeof(m_szStatus)-1,"%.1f%% (scroll)",nFactor * 100.0); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_RATIO_ID,m_szStatus); } // area della vista (client rect) m_rcClient.right = (int)nWidth; m_rcClient.bottom = (int)nHeight; // ricava le informazioni per il titolo char szTitle[_MAX_PATH+1] = {0}; int nColors = pImage->GetNumColors(); if(m_nViewType==VIEWTYPE_STRETCH) _snprintf(szFactor,sizeof(szFactor)-1,"%d%%",nRatio); _snprintf(szTitle, sizeof(szTitle)-1, "%s (%s) - %d x %d x %d%s", pDoc->GetFileName(), szFactor, pImage->GetWidth(), pImage->GetHeight(), (nColors > 256 || nColors==0) ? 16 : nColors, (nColors > 256 || nColors==0) ? "M" : "" ); pDoc->SetTitle(szTitle); // ricava le informazioni per la status bar if(m_pMainFrameStatusBar) { int nColors = pImage->GetNumColors(); _snprintf(m_szStatus, sizeof(m_szStatus)-1, "%d x %d x %d%s colors, %d bpp", pImage->GetWidth(), pImage->GetHeight(), (nColors > 256 || nColors==0) ? 16 : nColors, (nColors > 256 || nColors==0) ? "M" : "", pImage->GetBPP() ); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_INFO_ID,m_szStatus); UINT nMemUsed = pImage->GetMemUsed(); if(nMemUsed < 1024L) _snprintf(m_szStatus,sizeof(m_szStatus)-1,"%ld bytes",nMemUsed); else if(nMemUsed < 1048576L) _snprintf(m_szStatus,sizeof(m_szStatus)-1,"%0.1f KB",FDIV(((float)nMemUsed),1024.0f)); else _snprintf(m_szStatus,sizeof(m_szStatus)-1,"%0.2f MB",FDIV(((float)nMemUsed),1048576.0f)); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_MEM_ID,m_szStatus); strcpyn(m_szStatus,pImage->GetLibraryName(),sizeof(m_szStatus)); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_LIBRARY_ID,m_szStatus); } // area dell'immagine CRect rcImg(0,0,pImage->GetWidth(),pImage->GetHeight()); // se per la vista deve usare lo scroll, imposta le aree in modo tale che vengano visualizzate le barre di scorrimento if(m_nViewType==VIEWTYPE_SCROLL) m_rcClient = rcImg; // visualizza l'immagine scalata rispetto alla dimensione corrente della vista m_ImageDraw.DrawEx(pDC->GetSafeHdc(), &m_rcClient, &rcImg, NULL, FALSE, COLORONCOLOR, m_nDrawMode, SRCCOPY, m_bRebuildPalette ); m_bRebuildPalette = FALSE; }
/* OnUpdate() */ void CWallBrowserStretchView::OnUpdate(CView* pSender,LPARAM lHint,CObject* pHint) { CWaitCursor cursor; BOOL bHint = FALSE; static BOOL bTreeExpandedEx = FALSE; if(lHint & ONUPDATE_FLAG_TREEEXPANDEDEX) { TRACE("%s(%d): receiving ONUPDATE_FLAG_TREEEXPANDEDEX\n",__FILE__,__LINE__); bTreeExpandedEx = TRUE; } if(!bTreeExpandedEx) goto done; // cambio immagine/libreria correnti if((lHint & ONUPDATE_FLAG_FILECHANGED) || (lHint & ONUPDATE_FLAG_DEFAULTLIBRARY)) { TRACE("%s(%d): receiving ONUPDATE_FLAG_FILECHANGED || ONUPDATE_FLAG_DEFAULTLIBRARY\n",__FILE__,__LINE__); m_bLoaded = FALSE; CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument(); CImage* pImage = NULL; memset(m_szStatus,'\0',sizeof(m_szStatus)); if(pDoc) { // salva l'immagine se e' stata modificata if(pDoc->IsModified()) pDoc->SaveModified(m_szFileName); pImage = pDoc->GetImage(); if(pImage) { if(pDoc->HaveFileName()) { // ricava il nome del file da caricare _snprintf(m_szFileName, sizeof(m_szFileName)-1, "%s%s", pDoc->GetPathName(), pDoc->GetFileName() ); strcpyn(m_szStatus,"loading...",sizeof(m_szStatus)); if(m_pMainFrameStatusBar) m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_FILENAME_ID,m_szStatus); pDoc->SetTitle(m_szStatus); // carica l'immagine m_bHavePicture = TRUE; if(pImage->Load(m_szFileName)) { m_bLoaded = TRUE; strcpyn(m_szStatus,pDoc->GetFileName(),sizeof(m_szStatus)); } else { m_bLoaded = FALSE; _snprintf(m_szStatus,sizeof(m_szStatus)-1,"load failed - %s",pDoc->GetFileName()); } pDoc->SetTitle(m_szStatus); pDoc->SetPictureFlag(m_bLoaded); if(!m_bLoaded) pDoc->ResetFileName(); } } } // caricamento dell'immagine riuscito if(m_bLoaded) { if(m_pMainFrameStatusBar) { EnableMenu(); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_FILENAME_ID,m_szStatus); } } else // caricamento fallito { if(m_pMainFrameStatusBar) { DisableMenu(); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_FILENAME_ID,""); //m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_FILES_ID,""); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_INFO_ID,""); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_LIBRARY_ID,""); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_MEM_ID,""); //m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_PICTURES_ID,""); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_RATIO_ID,""); m_pMainFrameStatusBar->SetPaneText(ID_INDICATOR_ZOOM_ID,""); } } // aggiorna la GUI CWnd* pWnd = AfxGetMainWnd(); if(pWnd) { pWnd->SendMessage(WM_FILE_SAVE,FALSE,0L); pWnd->SendMessage(WM_FILE_SAVE_AS,m_bLoaded,0L); pWnd->SendMessage(WM_FILE_MOVE,m_bHavePicture,0L); pWnd->SendMessage(WM_FILE_DELETE,m_bHavePicture,0L); pWnd->SendMessage(WM_EDIT_COPY,m_bLoaded,0L); pWnd->SendMessage(WM_EDIT_PASTE,m_bLoaded ? ::IsClipboardFormatAvailable(CF_DIB) : FALSE,0L); pWnd->SendMessage(WM_EDIT_UNDO,FALSE,0L); pWnd->PostMessage(WM_EDIT_REDO,FALSE,0L); UndoEmpty(); RedoEmpty(); } // per evitare di cancellare il fondo se la nuova immagine e' piu' grande della precedente BOOL bEraseOnInvalidate = TRUE; // modalita' stretch, calcola la dimensione dello stretch if(m_nViewType==VIEWTYPE_STRETCH) { // modalita' visualizzazione (centrato/text) SetCenterMode(FALSE); SetMapMode(MM_TEXT); SetCursorZoomMode(CURSOR_MODE_NONE); // elimina le barre dello scroll CSize size(0,0); SetZoomSizes(size); bEraseOnInvalidate = m_bLoaded ? ((lHint & ONUPDATE_FLAG_DEFAULTLIBRARY) ? FALSE : TRUE) : TRUE; if(bEraseOnInvalidate && m_rcInvalid.right!=-1 && m_rcInvalid.bottom!=-1 && pImage) { double nRemains = 0.0; double nWidth = (double)pImage->GetWidth(); double nHeight = (double)pImage->GetHeight(); GetClientRect(&m_rcClient); if(nHeight > (double)m_rcClient.bottom) { nRemains = FDIV(nHeight,(double)m_rcClient.bottom); if(nRemains > 0.0) { nHeight = FDIV(nHeight,nRemains); nWidth = FDIV(nWidth,nRemains); } } if(nWidth > (double)m_rcClient.right) { nRemains = FDIV(nWidth,(double)m_rcClient.right); if(nRemains > 0.0) { nHeight = FDIV(nHeight,nRemains); nWidth = FDIV(nWidth,nRemains); } } if((int)nWidth >= m_rcInvalid.right && (int)nHeight >= m_rcInvalid.bottom) bEraseOnInvalidate = FALSE; } } // modalita' scroll else if(m_nViewType==VIEWTYPE_SCROLL) { // deve cancellare lo sfondo e riposizionare le barre dello scroll a 0,0 bEraseOnInvalidate = TRUE; POINT point = {0,0}; ScrollToPosition(point); NotifyRanges(); } // (ri)disegna l'immagine Invalidate(bEraseOnInvalidate); bHint = TRUE; } // click sull'immagine gia' selezionata (ma non attiva) if(lHint & ONUPDATE_FLAG_FILESELECTED) { TRACE("%s(%d): receiving ONUPDATE_FLAG_FILESELECTED\n",__FILE__,__LINE__); CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument(); if(pDoc) { CImage* pImage = pDoc->GetImage(); if(pImage && pImage->GetWidth() > 0 && pImage->GetHeight() > 0) { // aggiorna la GUI CWnd* pWnd = AfxGetMainWnd(); if(pWnd) { m_bLoaded = pDoc->GetPictureFlag(); pWnd->SendMessage(WM_FILE_SAVE,pDoc->IsModified(),0L); pWnd->SendMessage(WM_FILE_SAVE_AS,m_bLoaded,0L); pWnd->SendMessage(WM_FILE_MOVE,m_bHavePicture,0L); pWnd->SendMessage(WM_FILE_DELETE,m_bHavePicture,0L); pWnd->SendMessage(WM_EDIT_COPY,m_bLoaded,0L); pWnd->SendMessage(WM_EDIT_PASTE,m_bLoaded ? ::IsClipboardFormatAvailable(CF_DIB) : FALSE,0L); pWnd->SendMessage(WM_EDIT_UNDO,UndoEnabled(),0L); pWnd->PostMessage(WM_EDIT_REDO,RedoEnabled(),0L); } } } //Invalidate(FALSE); bHint = TRUE; } // eliminazione dell'immagine corrente if(lHint & ONUPDATE_FLAG_FILEDELETED) { TRACE("%s(%d): receiving ONUPDATE_FLAG_FILEDELETED\n",__FILE__,__LINE__); // se l'immagine e' stata modificata resetta il flag CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument(); if(pDoc->IsModified()) pDoc->SetModifiedFlag(FALSE); // aggiorna la GUI CWnd* pWnd = AfxGetMainWnd(); if(pWnd) { pWnd->SendMessage(WM_FILE_SAVE,FALSE,0L); pWnd->SendMessage(WM_FILE_SAVE_AS,FALSE,0L); pWnd->SendMessage(WM_FILE_MOVE,FALSE,0L); pWnd->SendMessage(WM_FILE_DELETE,FALSE,0L); pWnd->SendMessage(WM_EDIT_COPY,FALSE,0L); pWnd->SendMessage(WM_EDIT_PASTE,FALSE,0L); pWnd->SendMessage(WM_EDIT_UNDO,FALSE,0L); pWnd->PostMessage(WM_EDIT_REDO,FALSE,0L); UndoEmpty(); RedoEmpty(); } // deve disegnare il contenuto della nuova immagine o ripulire l'area client se era l'unica immagine della directory Invalidate(TRUE); // se il file era l'unico nella directory pDoc->SetTitle(pDoc->GetPathName()); bHint = TRUE; } // cambio della directory corrente if(lHint & ONUPDATE_FLAG_DIRCHANGED || lHint & ONUPDATE_FLAG_DIRSELECTED) { TRACE("%s(%d): receiving ONUPDATE_FLAG_DIRCHANGED || ONUPDATE_FLAG_DIRSELECTED\n",__FILE__,__LINE__); m_bLoaded = FALSE; // salva l'immagine se e' stata modificata CWallBrowserDoc* pDoc = (CWallBrowserDoc*)GetDocument(); if(pDoc) { if(pDoc->IsModified()) pDoc->SaveModified(m_szFileName); m_bLoaded = pDoc->GetPictureFlag(); } // aggiorna la GUI CWnd* pWnd = AfxGetMainWnd(); if(pWnd) { pWnd->SendMessage(WM_FILE_SAVE,FALSE,0L); pWnd->SendMessage(WM_FILE_SAVE_AS,m_bLoaded,0L); pWnd->SendMessage(WM_FILE_MOVE,m_bHavePicture,0L); pWnd->SendMessage(WM_FILE_DELETE,m_bHavePicture,0L); pWnd->SendMessage(WM_EDIT_COPY,m_bLoaded,0L); pWnd->SendMessage(WM_EDIT_PASTE,m_bLoaded ? ::IsClipboardFormatAvailable(CF_DIB) : FALSE,0L); pWnd->SendMessage(WM_EDIT_UNDO,FALSE,0L); pWnd->PostMessage(WM_EDIT_REDO,FALSE,0L); UndoEmpty(); RedoEmpty(); } // deve ripulire l'area client if(m_nViewType==VIEWTYPE_SCROLL) NotifyRanges(); Invalidate(TRUE); bHint = TRUE; } // e' stato svuotato lo stack per l'undo/redo if(lHint & ONUPDATE_FLAG_EMPTYSTACK) { TRACE("%s(%d): receiving ONUPDATE_FLAG_EMPTYSTACK\n",__FILE__,__LINE__); CWnd* pWnd = AfxGetMainWnd(); if(pWnd) { pWnd->SendMessage(WM_EDIT_UNDO,FALSE,0L); pWnd->PostMessage(WM_EDIT_REDO,FALSE,0L); } UndoEmpty(); RedoEmpty(); bHint = TRUE; } // e' stata cambiata la modalita' di visualizzazione (stretch/scroll) if(lHint & ONUPDATE_FLAG_VIEWTYPE) { TRACE("%s(%d): receiving ONUPDATE_FLAG_VIEWTYPE\n",__FILE__,__LINE__); m_nViewType = m_pWinAppEx->m_Config.GetNumber(WALLBROWSER_OPTIONS_KEY,WALLBROWSER_VIEWTYPE_KEY); if(m_nViewType==VIEWTYPE_SCROLL) { // modalita' visualizzazione (centrato/isotropic) SetCenterMode(TRUE); SetMapMode(MM_ANISOTROPIC); SetCursorZoomMode(CURSOR_MODE_BYCLICK); // risposiziona le barre dello scroll a 0,0 POINT point = {0,0}; ScrollToPosition(point); SetZoomMode(MODE_ZOOMOFF); NotifyRanges(); } else if(m_nViewType==VIEWTYPE_STRETCH) { // modalita' visualizzazione (centrato/text) SetCenterMode(FALSE); SetMapMode(MM_TEXT); SetCursorZoomMode(CURSOR_MODE_NONE); // elimina le barre dello scroll CSize size(0,0); SetZoomSizes(size); } // deve ridisegnare l'immagine ripulendo l'area client (dato che passa da una modalita' all'altra) Invalidate(TRUE); bHint = TRUE; } // e' stata cambiata la modalita' di disegno if((lHint & ONUPDATE_FLAG_DRAWSTRETCHDIBITS) || (lHint & ONUPDATE_FLAG_DRAWSTRETCHBLT) || (lHint & ONUPDATE_FLAG_DRAWVFWDRAWDIB)) { TRACE("%s(%d): receiving ONUPDATE_FLAG_DRAWSTRETCHDIBITS || ONUPDATE_FLAG_DRAWSTRETCHBLT || ONUPDATE_FLAG_DRAWVFWDRAWDIB\n",__FILE__,__LINE__); if(lHint & ONUPDATE_FLAG_DRAWSTRETCHDIBITS) m_nDrawMode = DRAW_STRETCHDIBITS; else if(lHint & ONUPDATE_FLAG_DRAWSTRETCHBLT) m_nDrawMode = DRAW_STRETCHBLT; else if (lHint & ONUPDATE_FLAG_DRAWVFWDRAWDIB) m_nDrawMode = DRAW_VFWDRAWDIB; else m_nDrawMode = DEFAULT_DRAWMODE; // deve ridisegnare l'immagine senza ripulire l'area client (cambia solo la modalita' di disegno, non quella di visualizzazione) Invalidate(FALSE); bHint = TRUE; } // e' stato cambiato il fattore di zoom if((lHint & ONUPDATE_FLAG_ZOOMIN) || (lHint & ONUPDATE_FLAG_ZOOMOUT) || (lHint & ONUPDATE_FLAG_ZOOMRESET)) { TRACE("%s(%d): receiving ONUPDATE_FLAG_ZOOMIN || ONUPDATE_FLAG_ZOOMOUT || ONUPDATE_FLAG_ZOOMRESET\n",__FILE__,__LINE__); if(lHint & ONUPDATE_FLAG_ZOOMIN) { SetZoomMode(MODE_ZOOMIN); TRACE("zoom ratio: %.2f\n",GetZoomRatio()); if(GetZoomRatio() <= 28.42) DoZoomIn(); } else if(lHint & ONUPDATE_FLAG_ZOOMOUT) { SetZoomMode(MODE_ZOOMOUT); TRACE("zoom ratio: %.2f\n",GetZoomRatio()); if(GetZoomRatio() >= 0.04) DoZoomOut(); } else if(lHint & ONUPDATE_FLAG_ZOOMRESET) { SetZoomMode(MODE_ZOOMOFF); NotifyRanges(); Invalidate(TRUE); } bHint = TRUE; } done: // classe base if(!bHint) CZoomView::OnUpdate(pSender,lHint,pHint); }
int main() { fixed a1 = INT2FIXED(100),a2 = INT2FIXED(3); printf("%f",FIXED2DOUBLE(FDIV(a1,a2))); }
static void Track_cbInfo( TrackState *pts ) { if( pts->theInfo.status == AEEGPS_ERR_NO_ERR || (pts->theInfo.status == AEEGPS_ERR_INFO_UNAVAIL && pts->theInfo.fValid) ) { #if MIN_BREW_VERSION(2,1) pts->pResp->lat = WGS84_TO_DEGREES( pts->theInfo.dwLat ); pts->pResp->lon = WGS84_TO_DEGREES( pts->theInfo.dwLon ); #else double wgsFactor; wgsFactor = FASSIGN_STR("186413.5111"); pts->pResp->lat = FASSIGN_INT(pts->theInfo.dwLat); pts->pResp->lat = FDIV(pts->pResp->lat, wgsFactor); pts->pResp->lon = FASSIGN_INT(pts->theInfo.dwLon); pts->pResp->lon = FDIV(pts->pResp->lon, wgsFactor); #endif /* MIN_BREW_VERSION 2.1 */ pts->pResp->height = pts->theInfo.wAltitude - 500; pts->pResp->wAzimuth = pts->orientInfo.wAzimuth; pts->pResp->heading = pts->theInfo.wHeading; pts->pResp->velocityHor = FMUL( pts->theInfo.wVelocityHor,0.25); pts->pResp->dwFixNum++; pts->pResp->nErr = SUCCESS; Track_Notify( pts ); if( (!pts->nPendingFixes || --pts->nPendingFixes > 0) && FALSE == pts->bSetForCancellation ) { if( pts->bModeAuto && pts->bModeLocal == FALSE ) { /* Try with local first */ Track_Local( pts ); } ISHELL_SetTimerEx( pts->pShell, pts->nTrackInterval * 1000, &pts->cbIntervalTimer ); } else { Track_Stop( pts ); } } else { if( pts->bModeAuto && pts->bModeLocal ) { /* Retry with TRACK_NETWORK */ Track_Network( pts ); Track_cbInterval( pts ); } else { DBGPRINTF("@Track_cbInfo status:%u", pts->theInfo.status); /* Inform the application of failure code. */ pts->pResp->nErr = pts->theInfo.status; Track_Notify( pts ); /* On timeout re-try. For other reasons bailout. */ if( pts->theInfo.status == AEEGPS_ERR_TIMEOUT ) { Track_cbInterval( pts ); } else { Track_Stop( pts ); } } } }