@@ -143,6 +143,7 @@ void CWinGlkWndTextBuffer::SizeWindow(CRect* pSize)
143143{
144144 CWinGlkWnd::SizeWindow (pSize);
145145 ClearFormatting (-1 );
146+ ResizeGraphics (pSize);
146147}
147148
148149void CWinGlkWndTextBuffer::ClearWindow (void )
@@ -538,39 +539,53 @@ bool CWinGlkWndTextBuffer::DrawGraphic(CWinGlkGraphic* pGraphic, int iValue1, in
538539 {
539540 if (pGraphic->m_pPixels && pGraphic->m_pHeader )
540541 {
541- // Get the width and height
542+ // Save the arguments needed later to recalculate the size of the graphic
543+ pGraphic->m_iDisplay = iValue1;
544+ pGraphic->m_ImageRule = iImageRule;
545+ pGraphic->m_MaxWidth = (double )iMaxWidth / 0x10000 ;
546+
542547 switch (iImageRule & imagerule_WidthMask)
543548 {
544549 case imagerule_WidthOrig:
545- iWidth = pGraphic->m_pHeader ->biWidth ;
550+ pGraphic-> m_iFixedWidth = pGraphic->m_pHeader ->biWidth ;
546551 break ;
547552 case imagerule_WidthFixed:
553+ pGraphic->m_iFixedWidth = iWidth;
554+ break ;
555+ case imagerule_WidthRatio:
556+ pGraphic->m_ScaleWidth = (double )iWidth / 0x10000 ;
548557 break ;
549558 default :
550559 return false ;
551560 }
552561 switch (iImageRule & imagerule_HeightMask)
553562 {
554563 case imagerule_HeightOrig:
555- iHeight = abs (pGraphic->m_pHeader ->biHeight );
564+ pGraphic-> m_iFixedHeight = abs (pGraphic->m_pHeader ->biHeight );
556565 break ;
557566 case imagerule_HeightFixed:
567+ pGraphic->m_iFixedHeight = iHeight;
568+ break ;
569+ case imagerule_AspectRatio:
570+ {
571+ double aspect = ((double )abs (pGraphic->m_pHeader ->biHeight )) / pGraphic->m_pHeader ->biWidth ;
572+ pGraphic->m_ScaleHeight = aspect * ((double )iHeight / 0x10000 );
573+ }
558574 break ;
559575 default :
560576 return false ;
561577 }
562578
579+ // Store the graphic
563580 if (m_TextBuffer.GetSize () == 0 )
564581 AddNewParagraph ();
565582 CParagraph* last = m_TextBuffer[m_TextBuffer.GetUpperBound ()];
566-
567- pGraphic->m_iWidth = iWidth;
568- pGraphic->m_iHeight = iHeight;
569- pGraphic->m_iDisplay = iValue1;
570-
571- // Store the graphic
572583 if (last->AddGraphic (pGraphic))
573584 {
585+ CRect ClientArea;
586+ GetClientRect (ClientArea);
587+ last->SetGraphicSize (pGraphic,&ClientArea);
588+
574589 ClearFormatting (m_TextBuffer.GetUpperBound ());
575590 bDelete = false ;
576591 return true ;
@@ -917,6 +932,12 @@ void CWinGlkWndTextBuffer::ClearFormatting(int iPara)
917932 }
918933}
919934
935+ void CWinGlkWndTextBuffer::ResizeGraphics (CRect* pWindowSize)
936+ {
937+ for (int i = 0 ; i < m_TextBuffer.GetSize (); i++)
938+ m_TextBuffer[i]->ResizeGraphics (pWindowSize);
939+ }
940+
920941template <class XCHAR > void CWinGlkWndTextBuffer::PaintInputBuffer (
921942 CWinGlkDC& dc, const XCHAR* input, int inputLen, CPaintInfo& Info)
922943{
@@ -1363,8 +1384,8 @@ void CWinGlkWndTextBuffer::CPaintInfo::DrawGraphic(CWinGlkGraphic* pGraphic, int
13631384
13641385 // Create a temporary DIBSection
13651386 CDibSection DibSection;
1366- DibSection.CreateBitmap (m_DeviceContext.GetSafeHdc (),
1367- pGraphic-> m_iWidth ,pGraphic-> m_iHeight ) ;
1387+ if (! DibSection.CreateBitmap (m_DeviceContext.GetSafeHdc (),pGraphic-> m_iWidth ,pGraphic-> m_iHeight ))
1388+ return ;
13681389 CBitmap* pOldBitmap = CDibSection::SelectDibSection (dcMem,&DibSection);
13691390
13701391 // Is this graphic being scaled?
@@ -1597,6 +1618,39 @@ bool CWinGlkWndTextBuffer::CParagraph::ClearFormatting(void)
15971618 return m_bClearAll;
15981619}
15991620
1621+ void CWinGlkWndTextBuffer::CParagraph::SetGraphicSize (CWinGlkGraphic* pGraphic, CRect* pWindowSize)
1622+ {
1623+ int width = pWindowSize->Width ();
1624+
1625+ if ((pGraphic->m_ImageRule & imagerule_WidthMask) == imagerule_WidthRatio)
1626+ pGraphic->m_iWidth = (int )(pGraphic->m_ScaleWidth * width);
1627+ else
1628+ pGraphic->m_iWidth = pGraphic->m_iFixedWidth ;
1629+
1630+ if ((pGraphic->m_ImageRule & imagerule_HeightMask) == imagerule_AspectRatio)
1631+ pGraphic->m_iHeight = (int )(pGraphic->m_ScaleHeight * pGraphic->m_iWidth );
1632+ else
1633+ pGraphic->m_iHeight = pGraphic->m_iFixedHeight ;
1634+
1635+ if (pGraphic->m_MaxWidth > 0.0 )
1636+ {
1637+ double ratio = (double )pGraphic->m_iHeight / (double )pGraphic->m_iWidth ;
1638+ if (pGraphic->m_iWidth > (width * pGraphic->m_MaxWidth ))
1639+ {
1640+ pGraphic->m_iWidth = (int )(width * pGraphic->m_MaxWidth );
1641+ pGraphic->m_iHeight = (int )(ratio * pGraphic->m_iWidth );
1642+ }
1643+ }
1644+ }
1645+
1646+ void CWinGlkWndTextBuffer::CParagraph::ResizeGraphics (CRect* pWindowSize)
1647+ {
1648+ for (int i = 0 ; i < m_InlineGraphics.GetSize (); i++)
1649+ SetGraphicSize (m_InlineGraphics[i],pWindowSize);
1650+ for (int i = 0 ; i < m_MarginGraphics.GetSize (); i++)
1651+ SetGraphicSize (m_MarginGraphics[i],pWindowSize);
1652+ }
1653+
16001654void CWinGlkWndTextBuffer::CParagraph::Format (CPaintInfo& Info)
16011655{
16021656 // Only format if there is no formatting already set up
0 commit comments