From: <sil...@li...> - 2003-01-02 21:19:15
|
Update of /cvsroot/silgraphite/silgraphite/contrib/fwviews In directory sc8-pr-cvs1:/tmp/cvs-serv14941/contrib/fwviews Modified Files: GrGraphics.cpp GrGraphics.h GrTxtSrc.cpp Log Message: Synchronized with FW, 20 Dec 2002, changelist #05908 Index: GrGraphics.cpp =================================================================== RCS file: /cvsroot/silgraphite/silgraphite/contrib/fwviews/GrGraphics.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GrGraphics.cpp 5 Nov 2002 21:29:08 -0000 1.1.1.1 --- GrGraphics.cpp 2 Jan 2003 21:18:41 -0000 1.2 *************** *** 15,19 **** /*********************************************************************************************** ! Include files ***********************************************************************************************/ #include "main.h" --- 15,19 ---- /*********************************************************************************************** ! Include files ***********************************************************************************************/ #include "main.h" *************** *** 23,46 **** DEFINE_THIS_FILE /*********************************************************************************************** ! Forward declarations ***********************************************************************************************/ /*********************************************************************************************** ! Local Constants and static variables ***********************************************************************************************/ /*********************************************************************************************** ! Two local classes, copied from AfGfx.h. Maybe we should move them to somewhere they can be shared more easily? ***********************************************************************************************/ /*********************************************************************************************** ! Constructors/Destructor ***********************************************************************************************/ GrGraphics::GrGraphics() { m_cref = 1; ! Init(); } --- 23,49 ---- DEFINE_THIS_FILE /*********************************************************************************************** ! Forward declarations ***********************************************************************************************/ /*********************************************************************************************** ! Local Constants and static variables ***********************************************************************************************/ /*********************************************************************************************** ! Two local classes, copied from AfGfx.h. Maybe we should move them to somewhere they can be shared more easily? ***********************************************************************************************/ /*********************************************************************************************** ! Constructors/Destructor ***********************************************************************************************/ GrGraphics::GrGraphics() { + m_hdc = NULL; m_cref = 1; ! Init(); ! m_hfont = NULL; ! m_hfontOld = NULL; } *************** *** 53,58 **** Assert(m_xInch == 0); Assert(m_yInch == 0); ! Assert(m_hfont == 0); ! Assert(m_hdc == 0); // m_chrp should contain zeros too; don't bother checking } --- 56,62 ---- Assert(m_xInch == 0); Assert(m_yInch == 0); ! Assert(m_hdc == NULL); ! Assert(m_hfont == NULL); ! Assert(m_hfontOld == NULL); // m_chrp should contain zeros too; don't bother checking } *************** *** 76,79 **** --- 80,96 ---- ReleaseDC(); } + Assert(!m_hfontOld); + if (m_hfontOld) + { + ::DeleteObject(m_hfontOld); + m_hfontOld = NULL; + } + Assert(!m_hfont); + if (m_hfont) + { + ::DeleteObject(m_hfont); + m_hfont = NULL; + } + ModuleEntry::ModuleRelease(); } *************** *** 81,85 **** /*********************************************************************************************** ! IVwGraphics Interface Methods ***********************************************************************************************/ /*---------------------------------------------------------------------------------------------- --- 98,102 ---- /*********************************************************************************************** ! IVwGraphics Interface Methods ***********************************************************************************************/ /*---------------------------------------------------------------------------------------------- *************** *** 108,112 **** MyGetClipRect(&rectClip); RECT rectIntersect; ! if(!::IntersectRect(&rectIntersect, &rectClip, &rect)) { // no intersection, nothing to do--but we (trivially) succeeded. --- 125,129 ---- MyGetClipRect(&rectClip); RECT rectIntersect; ! if (!::IntersectRect(&rectIntersect, &rectClip, &rect)) { // no intersection, nothing to do--but we (trivially) succeeded. *************** *** 125,130 **** /*---------------------------------------------------------------------------------------------- Set the foreground color used for lines, text ! Arguments: ! nRGB RGB color value ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::put_ForeColor(int nRGB) --- 142,147 ---- /*---------------------------------------------------------------------------------------------- Set the foreground color used for lines, text ! Arguments: ! nRGB RGB color value ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::put_ForeColor(int nRGB) *************** *** 145,150 **** /*---------------------------------------------------------------------------------------------- Background color, used for shape interior, text background ! Arguments: ! nRGB RGB color value or kclrTransparent ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::put_BackColor(int nRGB) --- 162,167 ---- /*---------------------------------------------------------------------------------------------- Background color, used for shape interior, text background ! Arguments: ! nRGB RGB color value or kclrTransparent ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::put_BackColor(int nRGB) *************** *** 256,260 **** If there are multiple dx values, the line is dashed. A segment of length prgdx[0] is first drawn, then a gap of length prgdx[1] is left, then a segment of length prgdx[2], ! and so forth until the specified width is reached (the last segment, if drawn, is truncated to the specified length). If all values in prgdx are used up, we start again at prgdx[0]. An odd number of segments --- 273,277 ---- If there are multiple dx values, the line is dashed. A segment of length prgdx[0] is first drawn, then a gap of length prgdx[1] is left, then a segment of length prgdx[2], ! and so forth until the specified width is reached (the last segment, if drawn, is truncated to the specified length). If all values in prgdx are used up, we start again at prgdx[0]. An odd number of segments *************** *** 285,289 **** stargdx.FormatAppend("%d,", *(prgdx + i)); } ! m_psts->OutputFormat("DrawHorzLine(%d, %d, %d, %d, %d, \"%s\", ptr)\n", xLeft, xRight, y, dyHeight, cdx, stargdx.Chars()); } --- 302,306 ---- stargdx.FormatAppend("%d,", *(prgdx + i)); } ! m_psts->OutputFormat("DrawHorzLine(%d, %d, %d, %d, %d, \"%s\", ptr)\n", xLeft, xRight, y, dyHeight, cdx, stargdx.Chars()); } *************** *** 367,371 **** StrAnsi staChar; staChar.Assign(prgch, cch); ! m_psts->OutputFormat("DrawText(%d, %d, %d, \"%s\", %d)\n", x, y, cch, staChar.Chars(), nStretch); } --- 384,388 ---- StrAnsi staChar; staChar.Assign(prgch, cch); ! m_psts->OutputFormat("DrawText(%d, %d, %d, \"%s\", %d)\n", x, y, cch, staChar.Chars(), nStretch); } *************** *** 404,408 **** cbrk++; } ! if(cbrk) { if (!::SetTextJustification(m_hdc, nStretch, cbrk)) --- 421,425 ---- cbrk++; } ! if (cbrk) { if (!::SetTextJustification(m_hdc, nStretch, cbrk)) *************** *** 483,488 **** rect.bottom = 0; } ! m_psts->OutputFormat("DrawTextExt(%d, %d, %d, \"%s\", %d, {%d, %d, %d, %d}, \"%s\")\n", x, y, cch, ! staChar.Chars(), uOptions, rect.left, rect.top, rect.right, rect.bottom, stargdx.Chars()); } --- 500,505 ---- rect.bottom = 0; } ! m_psts->OutputFormat("DrawTextExt(%d, %d, %d, \"%s\", %d, {%d, %d, %d, %d}, \"%s\")\n", x, y, cch, ! staChar.Chars(), uOptions, rect.left, rect.top, rect.right, rect.bottom, stargdx.Chars()); } *************** *** 492,496 **** CheckDc(); ! // check whether the text is visible, at least vertically RECT rectClip; --- 509,513 ---- CheckDc(); ! // check whether the text is visible, at least vertically RECT rectClip; *************** *** 566,570 **** StrAnsi staChar; staChar.Assign(prgch, cch); ! m_psts->OutputFormat("GetTextLeadWidth(%d, \"%s\", %d, %d, ptr)\n", cch, staChar.Chars(), ich, dxStretch); } --- 583,587 ---- StrAnsi staChar; staChar.Assign(prgch, cch); ! m_psts->OutputFormat("GetTextLeadWidth(%d, \"%s\", %d, %d, ptr)\n", cch, staChar.Chars(), ich, dxStretch); } *************** *** 572,576 **** CheckDc(); ! if (ich > cch) ThrowInternalError(kresInvalidArg, "ich out of range"); if (!ich) --- 589,593 ---- CheckDc(); ! if (ich > cch) ThrowInternalError(kresInvalidArg, "ich out of range"); if (!ich) *************** *** 647,651 **** if (!::GetTextMetrics(m_hdcMeasure, &tm)) ThrowInternalError(kresUnexpected, "GetTextMetrics failed"); ! *pxyFontEmSquare = tm.tmHeight - tm.tmInternalLeading; return kresOk; --- 664,668 ---- if (!::GetTextMetrics(m_hdcMeasure, &tm)) ThrowInternalError(kresUnexpected, "GetTextMetrics failed"); ! *pxyFontEmSquare = tm.tmHeight - tm.tmInternalLeading; return kresOk; *************** *** 655,659 **** Get glyph metrics for a glyph in the currently selected font. chw must be a glyph id. ----------------------------------------------------------------------------------------------*/ ! GrResult GrGraphics::GetGlyphMetrics(int chw, int * pxBoundingWidth, int * pyBoundingHeight, int * pxBoundingX, int * pyBoundingY, int * pxAdvanceX, int * pyAdvanceY) --- 672,676 ---- Get glyph metrics for a glyph in the currently selected font. chw must be a glyph id. ----------------------------------------------------------------------------------------------*/ ! GrResult GrGraphics::GetGlyphMetrics(int chw, int * pxBoundingWidth, int * pyBoundingHeight, int * pxBoundingX, int * pyBoundingY, int * pxAdvanceX, int * pyAdvanceY) *************** *** 671,678 **** CheckDc(); ! GLYPHMETRICS gm; const MAT2 mat2 = {{0,1}, {0,0}, {0,0}, {0,1}}; ! if (GDI_ERROR == ::GetGlyphOutline(m_hdcMeasure, chw, GGO_GLYPH_INDEX | GGO_METRICS, &gm, 0, NULL, &mat2)) { --- 688,695 ---- CheckDc(); ! GLYPHMETRICS gm; const MAT2 mat2 = {{0,1}, {0,0}, {0,0}, {0,1}}; ! if (GDI_ERROR == ::GetGlyphOutline(m_hdcMeasure, chw, GGO_GLYPH_INDEX | GGO_METRICS, &gm, 0, NULL, &mat2)) { *************** *** 698,702 **** /*---------------------------------------------------------------------------------------------- ! Get a table out of the font. ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::GetFontData(int nTableId, int * pcbTableSz, byte * prgb, int cbMax) --- 715,719 ---- /*---------------------------------------------------------------------------------------------- ! Get a table out of the font. Device independent. ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::GetFontData(int nTableId, int * pcbTableSz, byte * prgb, int cbMax) *************** *** 706,710 **** *pcbTableSz = -1; ! DWORD cbTableSz = ::GetFontData(m_hdcMeasure, nTableId, 0, NULL, 0); if (GDI_ERROR == cbTableSz) --- 723,727 ---- *pcbTableSz = -1; ! DWORD cbTableSz = ::GetFontData(m_hdcMeasure, nTableId, 0, NULL, 0); if (GDI_ERROR == cbTableSz) *************** *** 717,721 **** THROW(kresUnexpected); } ! return kresOk; } --- 734,738 ---- THROW(kresUnexpected); } ! return kresOk; } *************** *** 725,729 **** ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::XYFromGlyphPoint(int chw, int nPoint, int * pxRet, int * pyRet) ! { ChkGrArgPtr(pxRet); ChkGrOutPtr(pyRet); --- 742,746 ---- ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::XYFromGlyphPoint(int chw, int nPoint, int * pxRet, int * pyRet) ! { ChkGrArgPtr(pxRet); ChkGrOutPtr(pyRet); *************** *** 736,743 **** CheckDc(); ! GLYPHMETRICS gm; const MAT2 mat2 = {{0,1}, {0,0}, {0,0}, {0,1}}; ! WORD flag = GGO_GLYPH_INDEX | GGO_NATIVE; ! UINT cbBuf = ::GetGlyphOutline(m_hdcMeasure, chw, flag, &gm, 0, NULL, &mat2); if (cbBuf <= 0) --- 753,760 ---- CheckDc(); ! GLYPHMETRICS gm; const MAT2 mat2 = {{0,1}, {0,0}, {0,0}, {0,1}}; ! WORD flag = GGO_GLYPH_INDEX | GGO_NATIVE; ! UINT cbBuf = ::GetGlyphOutline(m_hdcMeasure, chw, flag, &gm, 0, NULL, &mat2); if (cbBuf <= 0) *************** *** 747,751 **** return WarnHr(kresOutOfMemory); if (GDI_ERROR == ::GetGlyphOutline(m_hdcMeasure, chw, flag, &gm, cbBuf, pGlyphData,&mat2)) ! ThrowInternalError(kresUnexpected, "Second GetGlyphOutline in XYFromGlyphPoint failed"); int dxLogPerInch = GetXInch(); --- 764,768 ---- return WarnHr(kresOutOfMemory); if (GDI_ERROR == ::GetGlyphOutline(m_hdcMeasure, chw, flag, &gm, cbBuf, pGlyphData,&mat2)) ! ThrowInternalError(kresUnexpected, "Second GetGlyphOutline in XYFromGlyphPoint failed"); int dxLogPerInch = GetXInch(); *************** *** 757,765 **** TTPOLYCURVE * pPolyCurve; pPolyHdr = (TTPOLYGONHEADER *)pGlyphData; ! int nCurPoint; nCurPoint = 0; // If the last curve in the polygon is a spline, the last point in this curve will ! // repeat the point from the the polygon header. This adds an extra point to the data // returned by Windows that is not in the TTF font file. Test to set nExtraPt is below. int nExtraPt = 0; --- 774,782 ---- TTPOLYCURVE * pPolyCurve; pPolyHdr = (TTPOLYGONHEADER *)pGlyphData; ! int nCurPoint; nCurPoint = 0; // If the last curve in the polygon is a spline, the last point in this curve will ! // repeat the point from the the polygon header. This adds an extra point to the data // returned by Windows that is not in the TTF font file. Test to set nExtraPt is below. int nExtraPt = 0; *************** *** 767,772 **** while ((BYTE *)pPolyHdr < (pGlyphData + cbBuf)) { ! if (nPoint == nCurPoint) ! { *pxRet = ::MulDiv(IntFromFixed(pPolyCurve->apfx[nPoint - nCurPoint].x), dxLogPerInch, dxPixPerInch); --- 784,789 ---- while ((BYTE *)pPolyHdr < (pGlyphData + cbBuf)) { ! if (nPoint == nCurPoint) ! { *pxRet = ::MulDiv(IntFromFixed(pPolyCurve->apfx[nPoint - nCurPoint].x), dxLogPerInch, dxPixPerInch); *************** *** 774,780 **** dyLogPerInch, dyPixPerInch); delete [] pGlyphData; ! return kresOk; ! } ! nCurPoint++; pPolyCurve = (TTPOLYCURVE *)(pPolyHdr + 1); if (pPolyHdr->dwType == TT_POLYGON_TYPE) --- 791,797 ---- dyLogPerInch, dyPixPerInch); delete [] pGlyphData; ! return kresOk; ! } ! nCurPoint++; pPolyCurve = (TTPOLYCURVE *)(pPolyHdr + 1); if (pPolyHdr->dwType == TT_POLYGON_TYPE) *************** *** 796,800 **** else nExtraPt = 0; ! if (nPoint < nCurPoint + pPolyCurve->cpfx - nExtraPt) { --- 813,817 ---- else nExtraPt = 0; ! if (nPoint < nCurPoint + pPolyCurve->cpfx - nExtraPt) { *************** *** 803,808 **** *pyRet = ::MulDiv(IntFromFixed(pPolyCurve->apfx[nPoint - nCurPoint].y), dyLogPerInch, dyPixPerInch); ! delete [] pGlyphData; ! return kresOk; } } --- 820,825 ---- *pyRet = ::MulDiv(IntFromFixed(pPolyCurve->apfx[nPoint - nCurPoint].y), dyLogPerInch, dyPixPerInch); ! delete [] pGlyphData; ! return kresOk; } } *************** *** 812,816 **** ThrowInternalError(kresUnexpected); } ! nCurPoint += pPolyCurve->cpfx - nExtraPt; pPolyCurve = (TTPOLYCURVE *)&pPolyCurve->apfx[pPolyCurve->cpfx]; --- 829,833 ---- ThrowInternalError(kresUnexpected); } ! nCurPoint += pPolyCurve->cpfx - nExtraPt; pPolyCurve = (TTPOLYCURVE *)&pPolyCurve->apfx[pPolyCurve->cpfx]; *************** *** 827,833 **** } pPolyHdr = (TTPOLYGONHEADER *)((BYTE *)pPolyHdr + pPolyHdr->cb); ! } ! delete [] pGlyphData; ThrowInternalError(kresUnexpected); return kresUnexpected; --- 844,850 ---- } pPolyHdr = (TTPOLYGONHEADER *)((BYTE *)pPolyHdr + pPolyHdr->cb); ! } ! delete [] pGlyphData; ThrowInternalError(kresUnexpected); return kresUnexpected; *************** *** 835,839 **** /*---------------------------------------------------------------------------------------------- ! Get the ascent of the currently selected font ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::get_FontAscent(int* pdy) --- 852,856 ---- /*---------------------------------------------------------------------------------------------- ! Get the ascent of the currently selected font, in logical units. ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::get_FontAscent(int* pdy) *************** *** 871,891 **** if (m_hdc) { ! if (*m_vhfontOld.Top()) ! ::SelectObject(m_hdc, *m_vhfontOld.Top()); ! if (m_hfontOldMeasure) ! ::SelectObject(m_hdcMeasure, m_hfontOldMeasure); ! m_vhfontOld.Pop(); ! ::RestoreDC(m_hdc, -1); // -1 means most recently saved ! if (m_hfont) { ! // NB this must be done after it is selected out of the DC, or we get a hard-to-find ! // GDI memory leak that causes weird drawing failures on W-98. ! ::DeleteObject(m_hfont); m_hfont = 0; } } m_hdc = NULL; m_hdcMeasure = NULL; ! Assert(m_vhfontOld.Size() == 0); // DC pushes equals pops return kresOk; --- 888,913 ---- if (m_hdc) { ! BOOL fSuccess; ! if (m_hfontOld) { ! // We have called SetFont at least once; the most recent font selected ! // is in m_hfont and is also the current one in the DC. Select the ! // original one back into the DC to prevent GDI memory leaks and similar problems. ! HFONT hfontPrev = (HFONT) ::SelectObject(m_hdc, m_hfontOld); ! Assert(hfontPrev == m_hfont); ! Assert(hfontPrev != m_hfontOld); m_hfont = 0; + ::DeleteObject(hfontPrev); + m_hfontOld = 0; } + Assert(m_hfont == 0); + if (m_hfontOldMeasure) + ::SelectObject(m_hdcMeasure, m_hfontOldMeasure); + fSuccess = ::RestoreDC(m_hdc, -1); // -1 means most recently saved + Assert(fSuccess); } m_hdc = NULL; m_hdcMeasure = NULL; ! Assert(m_vhrgnClipStack.Size() == 0); // Make sure pushes and pops match. return kresOk; *************** *** 893,897 **** /*---------------------------------------------------------------------------------------------- ! Get current actual or simulated X resolution ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::get_XUnitsPerInch(int * pxInch) --- 915,919 ---- /*---------------------------------------------------------------------------------------------- ! Get current actual or simulated X resolution. ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::get_XUnitsPerInch(int * pxInch) *************** *** 917,921 **** /*---------------------------------------------------------------------------------------------- ! Get current actual or simulated Y resolution ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::get_YUnitsPerInch(int * pyInch) --- 939,943 ---- /*---------------------------------------------------------------------------------------------- ! Get current actual or simulated Y resolution. ----------------------------------------------------------------------------------------------*/ GrResult GrGraphics::get_YUnitsPerInch(int * pyInch) *************** *** 957,965 **** const int cbFontOffset = offsetof(LgCharRenderProps, ttvBold); // if the info related to choosing HFONT is different, make a new HFONT ! if (!m_hfont || memcmp( ((byte *)pchrp) + cbFontOffset, ((byte *)&m_chrp) + cbFontOffset, isizeof(m_chrp) - cbFontOffset)) ! { // Remember the font we switch to. ! memcpy( ((byte *)&m_chrp) + cbFontOffset, ((byte *)pchrp) + cbFontOffset, isizeof(m_chrp) - cbFontOffset); --- 979,987 ---- const int cbFontOffset = offsetof(LgCharRenderProps, ttvBold); // if the info related to choosing HFONT is different, make a new HFONT ! if (!m_hfont || memcmp(((byte *)pchrp) + cbFontOffset, ((byte *)&m_chrp) + cbFontOffset, isizeof(m_chrp) - cbFontOffset)) ! { // Remember the font we switch to. ! memcpy(((byte *)&m_chrp) + cbFontOffset, ((byte *)pchrp) + cbFontOffset, isizeof(m_chrp) - cbFontOffset); *************** *** 998,1002 **** if (!hfont) ThrowHr(WarnHr(kresFail)); ! SetFont(hfont); } // Always set the colors. --- 1020,1024 ---- if (!hfont) ThrowHr(WarnHr(kresFail)); ! SetFont(hfont); } // Always set the colors. *************** *** 1006,1010 **** bool fOK = (AfGfx::SetTextColor(m_hdc, pchrp->clrFore) != CLR_INVALID); ! if(pchrp->clrBack == kclrTransparent) { // I can't find it documented anywhere, but it seems to be necessary to set --- 1028,1032 ---- bool fOK = (AfGfx::SetTextColor(m_hdc, pchrp->clrFore) != CLR_INVALID); ! if (pchrp->clrBack == kclrTransparent) { // I can't find it documented anywhere, but it seems to be necessary to set *************** *** 1037,1052 **** m_hdcMeasure = hdc; // default unless overridden by SetMeasureDc. Assert(m_hfont == 0); // Setting a new DC, we should not have any saved font info. ! SaveDC(hdc); ! m_vhfontOld.Push(0); ! //::SetMapMode(hdc, MM_TEXT); #if 0 // old code to force it to be twips. May be useful for ActiveX control ::SetWindowExtEx(hdc, 1440, 1440, NULL); // 72*20 twips per inch ! ::SetViewportExtEx(hdc, ::GetDeviceCaps(hdc, LOGPIXELSX), ! ::GetDeviceCaps(hdc, LOGPIXELSY), NULL); #endif // For the sake of being definite; rarely makes a difference; I think this is default ::SetPolyFillMode(hdc, ALTERNATE); ! // Need to set background mode to transparent so Graphite can draw overlapping glyphs ::SetBkMode(hdc, TRANSPARENT); --- 1059,1078 ---- m_hdcMeasure = hdc; // default unless overridden by SetMeasureDc. Assert(m_hfont == 0); // Setting a new DC, we should not have any saved font info. ! ! BOOL fSuccess; ! fSuccess = ::SaveDC(m_hdc); ! Assert(fSuccess); ! ! m_hfontOld = 0; ! //::SetMapMode(hdc, MM_TEXT); #if 0 // old code to force it to be twips. May be useful for ActiveX control ::SetWindowExtEx(hdc, 1440, 1440, NULL); // 72*20 twips per inch ! ::SetViewportExtEx(hdc, ::GetDeviceCaps(hdc, LOGPIXELSX), ! ::GetDeviceCaps(hdc, LOGPIXELSY), NULL); #endif // For the sake of being definite; rarely makes a difference; I think this is default ::SetPolyFillMode(hdc, ALTERNATE); ! // Need to set background mode to transparent so Graphite can draw overlapping glyphs ::SetBkMode(hdc, TRANSPARENT); *************** *** 1071,1076 **** GrResult GrGraphics::PushClipRect(RECT rcClip) { ! ::SaveDC(m_hdc); ! m_vhfontOld.Push(0); ::IntersectClipRect(m_hdc, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom); return kresOk; --- 1097,1126 ---- GrResult GrGraphics::PushClipRect(RECT rcClip) { ! HRGN hrgn; ! HRGN hrgnTemp; ! hrgnTemp = ::CreateRectRgn(0, 0, 0, 0); ! hrgn = hrgnTemp; ! int iResult = ::GetClipRgn(m_hdc, hrgn); ! // ::DeleteObject(hrgnTemp); This DeleteObject is not needed. ! if (iResult == -1) ! { ! // An error occurred. ! ThrowHr(WarnHr(E_FAIL)); ! } ! else if (iResult == 0) ! { ! // No current clip region ! ::DeleteObject(hrgn); // trash the temp one ! ! // The function succeeded and the given device context, has NO clipping region. ! hrgn = 0; ! } ! else ! { ! // The function succeeded and the given device context has a clipping region. ! // hrgn is now set to the previous clipping region. ! } ! ! m_vhrgnClipStack.Push(hrgn); ::IntersectClipRect(m_hdc, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom); return kresOk; *************** *** 1082,1111 **** GrResult GrGraphics::PopClipRect() { ! if (m_vhfontOld.Top()) ! ::SelectObject(m_hdc, m_vhfontOld.Top()); ! m_vhfontOld.Pop(); ! ::RestoreDC(m_hdc, -1); ! if (m_hfont) ! { ! // m_hfont is selected into the DC. Make sure it is current in the restored one, too. ! HFONT hfontPrev = (HFONT) ::SelectObject(m_hdc, m_hfont); ! if (!hfontPrev) ! ThrowHr(WarnHr(kresFail)); ! if (!m_vhfontOld.Top()) ! { ! // This is the first font selection we have made into this level; save the old one ! // to eventually select back into the DC before we RestoreDC. ! *m_vhfontOld.Top() = hfontPrev; ! } ! else ! { ! if (m_hfont != hfontPrev) ! { ! // It is neither the current font nor the one originally in this DC, so we ! // need to get rid of it. ! ::DeleteObject(hfontPrev); ! } ! } ! } return kresOk; } --- 1132,1143 ---- GrResult GrGraphics::PopClipRect() { ! // If *m_vhrgnClipStack.Top() is null, SelectClipRgn() will remove the clipping region. ! int iSuccess = ::SelectClipRgn(m_hdc, *m_vhrgnClipStack.Top()); ! if (!iSuccess || ERROR == iSuccess) ! ThrowHr(WarnHr(E_FAIL)); ! ! if (*m_vhrgnClipStack.Top()) ! ::DeleteObject(*m_vhrgnClipStack.Top()); ! m_vhrgnClipStack.Pop(); return kresOk; } *************** *** 1131,1135 **** /*********************************************************************************************** ! Utility methods ***********************************************************************************************/ --- 1163,1167 ---- /*********************************************************************************************** ! Utility methods ***********************************************************************************************/ *************** *** 1172,1188 **** ThrowHr(WarnHr(kresFail)); ! if (!m_vhfontOld.Top()) ! { ! // This is the first font selection we have made into this level; save the old one ! // to eventually select back into the DC before we RestoreDC. ! *m_vhfontOld.Top() = hfontPrev; ! } ! if (m_hfont) { // We have previously created a font and now need to delete it. // NB this must be done after it is selected out of the DC, or we get a hard-to-find // GDI memory leak that causes weird drawing failures on W-98. ::DeleteObject(m_hfont); } m_hfont = hfont; } --- 1204,1222 ---- ThrowHr(WarnHr(kresFail)); ! if (m_hfontOld) { // We have previously created a font and now need to delete it. // NB this must be done after it is selected out of the DC, or we get a hard-to-find // GDI memory leak that causes weird drawing failures on W-98. + Assert(m_hfont); + Assert(m_hfont == hfontPrev); ::DeleteObject(m_hfont); } + else + { + // This is the first font selection we have made into this level; save the old one + // to eventually select back into the DC before we RestoreDC. + m_hfontOld = hfontPrev; + } m_hfont = hfont; } *************** *** 1194,1198 **** void GrGraphics::CheckDc() { ! if (!m_hdc) { Assert(false); --- 1228,1232 ---- void GrGraphics::CheckDc() { ! if (!m_hdc) { Assert(false); *************** *** 1212,1221 **** return; } ! if(GetClipBox(m_hdc, prc) == ERROR) ThrowInternalError(E_FAIL, L"Could not get clip rectangle"); } - #include <vector_i.cpp> ! template Vector<HFONT>; // VecHfont; --- 1246,1254 ---- return; } ! if (GetClipBox(m_hdc, prc) == ERROR) ThrowInternalError(E_FAIL, L"Could not get clip rectangle"); } #include <vector_i.cpp> ! template Vector<HRGN>; // VecHRgn; Index: GrGraphics.h =================================================================== RCS file: /cvsroot/silgraphite/silgraphite/contrib/fwviews/GrGraphics.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GrGraphics.h 5 Nov 2002 21:29:08 -0000 1.1.1.1 --- GrGraphics.h 2 Jan 2003 21:18:42 -0000 1.2 *************** *** 58,65 **** virtual GrResult GetClipRect(int * pxLeft, int * pyTop, int * pxRight, int * pyBottom); virtual GrResult GetFontEmSquare(int * pxyFontEmSquare); ! virtual GrResult GetGlyphMetrics(int chw, int * psBoundingWidth, int * pyBoundingHeight, int * pxBoundingX, int * pyBoundingY, int * pxAdvanceX, int * pyAdvanceY); ! virtual GrResult GetFontData(int nTableId, int * pcbTableSz, byte * prgb, int cbMax); virtual GrResult XYFromGlyphPoint(int chw, int nPoint, int * pxRet, int * pyRet); virtual GrResult get_FontAscent(int* pdy); --- 58,65 ---- virtual GrResult GetClipRect(int * pxLeft, int * pyTop, int * pxRight, int * pyBottom); virtual GrResult GetFontEmSquare(int * pxyFontEmSquare); ! virtual GrResult GetGlyphMetrics(int chw, int * psBoundingWidth, int * pyBoundingHeight, int * pxBoundingX, int * pyBoundingY, int * pxAdvanceX, int * pyAdvanceY); ! virtual GrResult GetFontData(int nTableId, int * pcbTableSz, byte * prgb, int cbMax); virtual GrResult XYFromGlyphPoint(int chw, int nPoint, int * pxRet, int * pyRet); virtual GrResult get_FontAscent(int* pdy); *************** *** 106,116 **** Rect m_rcClip; ! typedef Vector<HFONT> VecHfont; ! // Each time we SaveDC, we push a zero into this. Each time we set a font, ! // if the top item is zero we save the previous font at the end. Each time we ! // RestoreDC, if the end value is non-zero,we select it back into the DC ! // before doing the restore. ! VecHfont m_vhfontOld; // If we have a distinct measure DC, we save its original font here to restore into it. HFONT m_hfontOldMeasure; --- 106,114 ---- Rect m_rcClip; ! typedef Vector<HRGN> VecHRgn; ! // Stack of clip regions used by PushClipRect and PopClipRect. ! VecHRgn m_vhrgnClipStack; ! HFONT m_hfontOld; // original font to restore into the DC. // If we have a distinct measure DC, we save its original font here to restore into it. HFONT m_hfontOldMeasure; *************** *** 128,134 **** int IntFromFixed(FIXED f) { ! if (f.fract >= 0x8000) return(f.value + 1); ! else return(f.value); } --- 126,132 ---- int IntFromFixed(FIXED f) { ! if (f.fract >= 0x8000) return(f.value + 1); ! else return(f.value); } Index: GrTxtSrc.cpp =================================================================== RCS file: /cvsroot/silgraphite/silgraphite/contrib/fwviews/GrTxtSrc.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GrTxtSrc.cpp 5 Nov 2002 21:29:08 -0000 1.1.1.1 --- GrTxtSrc.cpp 2 Jan 2003 21:18:42 -0000 1.2 *************** *** 11,19 **** Description: An implementation of ITextSource based on having a VwStringBoxMain for each span in a ! paragraph (or one for the whole paragraph, if no embedded spans), and a list of strings. -------------------------------------------------------------------------------*//*:End Ignore*/ //:>******************************************************************************************** ! //:> Include files //:>******************************************************************************************** #include "main.h" --- 11,19 ---- Description: An implementation of ITextSource based on having a VwStringBoxMain for each span in a ! paragraph (or one for the whole paragraph, if no embedded spans), and a list of strings. -------------------------------------------------------------------------------*//*:End Ignore*/ //:>******************************************************************************************** ! //:> Include files //:>******************************************************************************************** #include "main.h" *************** *** 25,29 **** //:>******************************************************************************************** ! //:> Forward declarations //:>******************************************************************************************** --- 25,29 ---- //:>******************************************************************************************** ! //:> Forward declarations //:>******************************************************************************************** *************** *** 45,49 **** m_prgchText = NewObj OLECHAR[m_cchLength]; memcpy(m_prgchText, pszText, isizeof(OLECHAR) * m_cchLength); ! pszText[m_cchLength] = 0; // zero-terminate memcpy(&m_chrp, &chrp, isizeof(LgCharRenderProps)); --- 45,49 ---- m_prgchText = NewObj OLECHAR[m_cchLength]; memcpy(m_prgchText, pszText, isizeof(OLECHAR) * m_cchLength); ! m_prgchText[m_cchLength] = 0; // zero-terminate memcpy(&m_chrp, &chrp, isizeof(LgCharRenderProps)); *************** *** 88,91 **** --- 88,93 ---- memcpy(pchrp, &m_chrp, isizeof(LgCharRenderProps)); + *pichMin = 0; + *pichLim = m_cchLength; return kresOk; } *************** *** 110,113 **** --- 112,117 ---- { memset(pchrp, 0, isizeof(LgParaRenderProps)); + *pichMin = 0; + *pichLim = m_cchLength; Assert(false); ThrowInternalError(kresNotImpl); |