Exemple #1
0
void
MarkupParser::AppendMarkup(const TextDocumentRef& document, const BString& text)
{
	fTextDocument.SetTo(document);

	fCurrentCharacterStyle = &fNormalStyle;
	fCurrentParagraphStyle = &fParagraphStyle;

	fCurrentParagraph = Paragraph(*fCurrentParagraphStyle);
	fSpanStartOffset = 0;

	_ParseText(text);

	fTextDocument.Unset();
}
Exemple #2
0
void GdbLoader::ParseTrack(const CGdbTrackHdr * _pTrack, size_t _cOffset, size_t _cNextOffset, size_t _cFileSize, bool _bRestore)
{
    const BYTE * const pEnd = reinterpret_cast<const BYTE *> (_pTrack) + (_cNextOffset - _cOffset);

    const size_t cNameLen = ::strlen (_pTrack->strName);
    std::string strLabel;
    if (cNameLen)
        _ParseText (strLabel, _pTrack->strName, cNameLen);

    const size_t cOffset2 = _cOffset + sizeof (CGdbRecordHdr) + cNameLen + 1;
    const size_t cOffsetPoints = cOffset2 + sizeof (CGdbTrack2);

    const CGdbTrack2 * const p2 = reinterpret_cast<const CGdbTrack2 *> (reinterpret_cast<const BYTE *> (_pTrack->strName) + cNameLen + 1);
    const BYTE * p = reinterpret_cast<const BYTE *> (p2) + sizeof (CGdbTrack2);

    std::vector<point_t> points(p2->dwPoints);
    std::vector<trackpoint_info_t> points_extra(p2->dwPoints);

    for (size_t cPoint = 0; cPoint < p2->dwPoints; ++ cPoint) {
        if (p + 2*sizeof (LONG) + sizeof (BYTE) > pEnd) {
            /*			if (_bRestore == false) {
            				if (Silent () || YesNoMsgBox ("Track '%s' is probably damaged. Would you like to restore it?", strLabel.c_str ())) {
            					points.clear ();
            					points_extra.clear ();

            					// Try to read track record up to the very end of file.
            					const char * const pRecord = GetFilePart (_cOffset, _cFileSize);
            					if (pRecord == NULL)
            						return;
            					const CGdbTrackHdr * const pTrack = reinterpret_cast<const CGdbTrackHdr *> (pRecord);
            					ParseTrack (pTrack, _cOffset, _cFileSize, _cFileSize, true);
            					return;
            				}
            			}

            			// NOTE: the header defines incorrect number of points.
            			ReportWarning ("Track '%s' is damaged. It will be restored.", strLabel.c_str ());

            			points.resize (cPoint);
            			points_extra.resize (cPoint);*/
            break;
        }

        xyz_t xyz;
        _ReadXYZ(p, xyz, pEnd);

        // Date/time in seconds since 1 Jan 1970.
        const BYTE btHasTime = * p;
        p += sizeof (btHasTime);
        DWORD dwTime = 0;
        if (btHasTime && p < (BYTE *) pEnd) {
            dwTime = * reinterpret_cast<const DWORD *> (p);
            p += sizeof (dwTime);
        }

        // Depth.
        const BYTE btHasDepth = * p;
        p += sizeof (btHasDepth);
        double dfDepth = 0;
        if (btHasDepth && p < (BYTE *) pEnd) {
            // In m.
            dfDepth = * reinterpret_cast<const double *> (p);
            p += sizeof (dfDepth);
        }

        // Temperature.
        const BYTE btHasTemperature = * p;
        p += sizeof (btHasTemperature);
        double dfTemperature = 0;
        if (btHasTemperature && p < (BYTE *) pEnd) {
            // In C degrees.
            dfTemperature = * reinterpret_cast<const double *> (p);
            p += sizeof (dfTemperature);
        }

        point_t & point = points[cPoint];
        point.x = xyz.lX*180.f/(1UL << 31);
        point.y = xyz.lY*180.f/(1UL << 31);

        trackpoint_info_t & point_extra = points_extra[cPoint];

        if (xyz.btHasAltitude) {
            point_extra.wFlags |= trackpoint_info_t::defAltitude;
            point_extra.fAltitude = (float)xyz.dfAltitude;
        }
        if (btHasTime) {
            point_extra.wFlags |= trackpoint_info_t::defTime;
            point_extra.dtTime = dwTime/24./60./60. + 25569.;
        }
        if (btHasDepth) {
            point_extra.wFlags |= trackpoint_info_t::defDepth;
            point_extra.fDepth = (float)dfDepth;
        }
        if (btHasTemperature) {
            point_extra.wFlags |= trackpoint_info_t::defTemperature;
            point_extra.fTemperature = (float)dfTemperature;
        }
    }

    // Get links.
    std::string strLink;
    _ParseLinks(strLink, p, pEnd);

    //
    // Add the track to the map.
    //
    HSHAPE hShape = ::AddShape(m_hMap, SHAPETYPE_TRACK);
    ::SetShapeInfoStr(hShape, SHAPEINFO_TEXT, (char*)strLabel.c_str());
    for (size_t i = 0; i < points.size(); i++) {
        point_t point = points.at(i);
        HPOINT hPoint = ::AddPoint(hShape, point.y, point.x);
        trackpoint_info_t & point_extra = points_extra[i];
        if (point_extra.wFlags & trackpoint_info_t::defAltitude)
            ::SetPointInfoDbl(hPoint, POINTINFO_ELEV, point_extra.fAltitude);
        else if (point_extra.wFlags & trackpoint_info_t::defDepth)
            ::SetPointInfoDbl(hPoint, POINTINFO_ELEV, -point_extra.fDepth);
        if (point_extra.wFlags & trackpoint_info_t::defTime) {
            char dt[64];
            _GetISOTime(point_extra.dtTime, dt, 64);
            ::SetPointInfoStr(hPoint, POINTINFO_DATETIME, dt);
        }
        if (point_extra.wFlags & trackpoint_info_t::defTemperature)
            ::SetPointInfo(hPoint, POINTINFO_TEMP, (int)point_extra.fTemperature);
    }
}
Exemple #3
0
void GdbLoader::ParseRoute(const CGdbRouteHdr * _pRoute, size_t _cOffset, size_t _cNextOffset)
{
    const BYTE * const pEnd = reinterpret_cast<const BYTE *> (_pRoute) + (_cNextOffset - _cOffset);

    const size_t cNameLen = ::strlen (_pRoute->strName);

    const BYTE * p = reinterpret_cast<const BYTE *> (reinterpret_cast<const BYTE *> (_pRoute->strName) + cNameLen + 1);

    // Is route auto-named by MapSource?
    const BYTE btAutoNamed = * reinterpret_cast<const BYTE *> (p);
    p += sizeof (btAutoNamed);

    // ??
    const BYTE btMinMaxNotDefined = * reinterpret_cast<const BYTE *> (p);
    p += sizeof (btMinMaxNotDefined);

    if (! btMinMaxNotDefined) {
        xyz_t xyzMax;
        _ReadXYZ (p, xyzMax, pEnd);

        xyz_t xyzMin;
        _ReadXYZ (p, xyzMin, pEnd);
    }

    // Links.
    const DWORD dwLinks = * reinterpret_cast<const DWORD *> (p);
    p += sizeof (dwLinks);

    std::vector<point_t> points;
    points.reserve(dwLinks);

    std::vector<point_t> rpoints;
    rpoints.reserve(dwLinks);

    point_t last_point;
    bool bLastPointDefined = false;

    for (size_t cLink = 0; cLink < dwLinks; ++ cLink) {
        const char * const strWaypointName = reinterpret_cast<const char *> (p);
        const size_t cWaypointNameLen = ::strlen (strWaypointName);
        p += cWaypointNameLen + 1;

        const CGdbRouteLink2 * const pLink2 = reinterpret_cast<const CGdbRouteLink2 *> (p);
        p += sizeof (CGdbRouteLink2);

        if (* p == 0xFF)
            // ?? It seems there are 8 0xFF's inserted in routes created on GPS devices.
            p += 8;

        const CGdbRouteLink3 * const pLink3 = reinterpret_cast<const CGdbRouteLink3 *> (p);
        p += sizeof (CGdbRouteLink3);

        // Link points.
        size_t cPoint;
        for (cPoint = 0; cPoint < pLink3->dwPoints; ++ cPoint) {
            xyz_t xyz;
            _ReadXYZ (p, xyz, pEnd);

            point_t point;
            point.x = xyz.lX*180.f/(1UL << 31);
            point.y = xyz.lY*180.f/(1UL << 31);

            // NOTE: the last point of link is equal to the first one of the next link.
            if (cPoint + 1 < pLink3->dwPoints) {
                points.push_back (point);

                /*				routepoint_info_t rpoint;
                				if (cPoint == 0) {
                					string_t strWptName;
                					_ParseText (strWptName, strWaypointName, cWaypointNameLen);
                					const name2wpt_t::const_iterator i = m_name2wpt.find (strWptName);
                					if (i != m_name2wpt.end ())
                						rpoint.pWaypoint = i->second;
                				}
                				rpoints.push_back (rpoint);*/
            } else {
                last_point = point;
                bLastPointDefined = true;
            }
        }

        // Save the name and position of the last point.
        if (cLink + 1 == dwLinks) {
            if (bLastPointDefined)
                points.push_back (last_point);

            /*			routepoint_info_t rpoint;
            			if (cPoint == 0) {
            				const string_t strWptName (strWaypointName, cWaypointNameLen);
            				const name2wpt_t::const_iterator i = m_name2wpt.find (strWptName);
            				if (i != m_name2wpt.end ())
            					rpoint.pWaypoint = i->second;
            			}
            			rpoints.push_back (rpoint);*/
        }

        // Separator.
        const BYTE btLastLink = * p;
        p += sizeof (btLastLink);

        if (cLink + 1 < dwLinks) {
            xyz_t xyzLinkMax;
            _ReadXYZ (p, xyzLinkMax, pEnd);

            xyz_t xyzLinkMin;
            _ReadXYZ (p, xyzLinkMin, pEnd);
        }

        if (m_b2ndVersion) {
            // ?? 0xFF
            p += 8;
        } else if (m_b3rdVersion) {
            // ?? 0xFF
            p += 8;
            // ?? 0x00
            p += 2;
        }
    }

    // Get links.
    std::string strLink;
    _ParseLinks (strLink, p, pEnd);

    std::string strComment;
    if (m_b3rdVersion) {
        // TODO: 0E 00 00 00 00
        p += 5;

        _ParseText(strComment, (const char *)p, pEnd - p);
        p = pEnd;
    }

    //
    // Add the route to the map.
    //
    HSHAPE hShape = ::AddShape(m_hMap, SHAPETYPE_ROUTE);

    std::string txt;
    if (cNameLen) {
        _ParseText(txt, _pRoute->strName, cNameLen);
        ::SetShapeInfoStr(hShape, SHAPEINFO_TEXT, (char*)txt.c_str());
    }
    ::SetShapeInfoStr(hShape, SHAPEINFO_COMMENT, (char*)strComment.c_str());
    for (size_t i = 0; i < points.size(); i++) {
        point_t point = points.at(i);
        ::AddPoint(hShape, point.y, point.x);
    }
}
Exemple #4
0
void GdbLoader::ParseWaypoint(const CGdbWaypointHdr * _pWP, size_t _cOffset, size_t _cNextOffset)
{
    const BYTE * const pEnd = reinterpret_cast<const BYTE *> (_pWP) + (_cNextOffset - _cOffset);

    const size_t cNameLen = ::strlen (_pWP->strName);
    const CGdbWaypoint2 * const p2 = reinterpret_cast<const CGdbWaypoint2 *> (reinterpret_cast<const BYTE *> (_pWP->strName) + cNameLen + 1);

    point_t point;
    point.x = p2->lX * 180.f / (1UL << 31);
    point.y = p2->lY * 180.f / (1UL << 31);

    //
    // Parse the variable part of waypoint.
    //
    const BYTE * p = reinterpret_cast<const BYTE *> (p2) + sizeof (CGdbWaypoint2);

    // Get altitude.
    const BYTE btHasAltitude = * p;
    p += sizeof (btHasAltitude);
    double dfAltitude = 0;
    if (btHasAltitude) {
        // In m.
        dfAltitude = * reinterpret_cast<const double *> (p);
        p += sizeof (dfAltitude);
    }

    // Get comment.
    const char * const strComment = reinterpret_cast<const char *> (p);
    const size_t cCommentLen = ::strlen (strComment);
    p += cCommentLen + 1;

    // Get proximity.
    const BYTE btHasProximity = * p;
    p += sizeof (btHasProximity);
    double dfProximity = 0;
    if (btHasProximity) {
        // In m.
        dfProximity = * reinterpret_cast<const double *> (p);
        p += sizeof (dfProximity);
    }

    // How to display:
    // 0x0 - symbol, 0x1 - symbol & name, 0x2 - symbol and description.
    const DWORD dwShow = * reinterpret_cast<const DWORD *> (p);
    p += sizeof (dwShow);

    // Color?
    const DWORD dwColor = * reinterpret_cast<const DWORD *> (p);
    p += sizeof (dwColor);

    // Get type.
    const DWORD dwType = * reinterpret_cast<const DWORD *> (p);
    p += sizeof (dwType);
    /*	WORD wPOIType = GarminWPT2POIType (dwType);
    	if (wPOIType != 0 && m_pMap->pTypeSet == & g_tsNull) {
    		// TODO: better solution is required!
    		if (g_map.pTypeSet == & g_tsNull)
    			m_pMap->pTypeSet = & g_tsGarmin;
    		else if (g_map.pTypeSet == & g_tsGarmin || g_map.pTypeSet == & g_tsRussa || g_map.pTypeSet == & g_tsNavitel)
    			m_pMap->pTypeSet = g_map.pTypeSet;
    		else
    			wPOIType = 0;
    	}*/

    const char * const strCity = reinterpret_cast<const char *> (p);
    const size_t cCityLen = ::strlen (strCity);
    p += cCityLen + 1;

    const char * const strState = reinterpret_cast<const char *> (p);
    const size_t cStateLen = ::strlen (strState);
    p += cStateLen + 1;

    const char * const strFacility = reinterpret_cast<const char *> (p);
    const size_t cFacilityLen = ::strlen (strFacility);
    p += cFacilityLen + 1;

    const BYTE btMapLine8 = * reinterpret_cast<const BYTE *> (p);
    p += sizeof (btMapLine8);

    // Get depth.
    const BYTE btHasDepth = * p;
    p += sizeof (btHasDepth);
    double dfDepth = 0;
    if (btHasDepth) {
        // In m.
        dfDepth = * reinterpret_cast<const double *> (p);
        p += sizeof (dfDepth);
    }

    // Unknown = 0x0000.
    const WORD wUnknown0 = * reinterpret_cast<const WORD *> (p);
    p += sizeof (wUnknown0);

    // Predicted leg time in seconds for auto-routed routes.
    const DWORD dwLegTime = * reinterpret_cast<const DWORD *> (p);
    p += sizeof (dwLegTime);

    // Routing directions.
    const char * strRoutingDirections = reinterpret_cast<const char *> (p);
    const size_t cRoutingDirectionsLen = ::strlen (strRoutingDirections);
    p += cRoutingDirectionsLen + 1;

    // Get link.
    std::string strLink;
    _ParseLinks (strLink, p, pEnd);

    // Categories.
    const WORD wCategories = * reinterpret_cast<const WORD *> (p);
    p += sizeof (wCategories);

    // Get temperature.
    const BYTE btHasTemperature = * p;
    p += sizeof (btHasTemperature);
    double dfTemperature = 0;
    if (btHasTemperature) {
        // In C degrees.
        dfTemperature = * reinterpret_cast<const double *> (p);
        p += sizeof (dfTemperature);
    }

    // Date/time in seconds since 1 Jan 1970
    const BYTE btHasTime = * p;
    p += sizeof (btHasTime);
    DWORD dwTime = 0;
    if (btHasTime) {
        dwTime = * reinterpret_cast<const DWORD *> (p);
        p += sizeof (dwTime);
    }

    if (m_b3rdVersion)
        // TODO: unknown fields, zeroes.
        p += 6;

    HSHAPE hShape = ::AddShape(m_hMap, SHAPETYPE_WAYPOINT);
    std::string txt;
    if (cNameLen) {
        _ParseText(txt, _pWP->strName, cNameLen);
        ::SetShapeInfoStr(hShape, SHAPEINFO_TEXT, (char*)txt.c_str());
    }
    if (cCommentLen) {
        _ParseText(txt, strComment, cCommentLen);
        ::SetShapeInfoStr(hShape, SHAPEINFO_COMMENT, (char*)txt.c_str());
    }
    if (btHasProximity) {
        ::SetShapeInfoDbl(hShape, SHAPEINFO_PROXIMITY, dfProximity);
    }
    if (btHasTemperature) {
        ::SetShapeInfo(hShape, SHAPEINFO_TEMP, (int)dfTemperature);
    }
    if (btHasAltitude) {
        ::SetShapeInfoDbl(hShape, SHAPEINFO_ELEV, dfAltitude);
    } else if (btHasDepth) {
        ::SetShapeInfoDbl(hShape, SHAPEINFO_ELEV, -dfDepth);
    }
    if (btHasTime) {
        double dtTime = dwTime/24./60./60. + 25569.;
        char dt[64];
        _GetISOTime(dtTime, dt, 64);
        ::SetShapeInfoStr(hShape, SHAPEINFO_DATETIME, dt);
    }
    HPOINT pt = ::GetPoint(hShape, 0);
    if (pt) {
        ::SetCoord(pt, point.y, point.x);
    }
}