Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/buffer/out/OutputCellIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ OutputCellIterator& OutputCellIterator::operator++()
}
case Mode::CharInfo:
{
// Walk forward by one because charinfos are just the legacy version of cells and prealigned to columns
// Walk forward by one because char infos are just the legacy version of cells and prealigned to columns
_pos++;
if (operator bool())
{
Expand Down
51 changes: 0 additions & 51 deletions src/host/dbcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "misc.h"

#include "../types/inc/convert.hpp"
#include "../types/inc/GlyphWidth.hpp"

#include "../interactivity/inc/ServiceLocator.hpp"

Expand Down Expand Up @@ -47,56 +46,6 @@ bool CheckBisectStringA(_In_reads_bytes_(cbBuf) PCHAR pchBuf, _In_ DWORD cbBuf,
return false;
}

// Routine Description:
// - This routine removes the double copies of characters used when storing DBCS/Double-wide characters in the text buffer.
// - It munges up Unicode cells that are about to be returned whenever there is DBCS data and a raster font is enabled.
// - This function is ONLY FOR COMPATIBILITY PURPOSES. Please do not introduce new usages.
// Arguments:
// - buffer - The buffer to walk and fix
// Return Value:
// - The length of the final modified buffer.
DWORD UnicodeRasterFontCellMungeOnRead(const std::span<CHAR_INFO> buffer)
{
// Walk through the source CHAR_INFO and copy each to the destination.
// EXCEPT for trailing bytes (this will de-duplicate the leading/trailing byte double copies of the CHAR_INFOs as stored in the buffer).

// Set up indices used for arrays.
DWORD iDst = 0;

// Walk through every CHAR_INFO
for (DWORD iSrc = 0; iSrc < buffer.size(); iSrc++)
{
// If it's not a trailing byte, copy it straight over, stripping out the Leading/Trailing flags from the attributes field.
auto& src{ til::at(buffer, iSrc) };
if (!WI_IsFlagSet(src.Attributes, COMMON_LVB_TRAILING_BYTE))
{
auto& dst{ til::at(buffer, iDst) };
dst = src;
WI_ClearAllFlags(dst.Attributes, COMMON_LVB_SBCSDBCS);
iDst++;
}

// If it was a trailing byte, we'll just walk past it and keep going.
}

// Zero out the remaining part of the destination buffer that we didn't use.
const auto cchDstToClear = gsl::narrow<DWORD>(buffer.size()) - iDst;

if (cchDstToClear > 0)
{
const auto pciDstClearStart = buffer.data() + iDst;
ZeroMemory(pciDstClearStart, cchDstToClear * sizeof(CHAR_INFO));
}

// Add the additional length we just modified.
iDst += cchDstToClear;

// now that we're done, we should have copied, left alone, or cleared the entire length.
FAIL_FAST_IF(iDst != buffer.size());

return iDst;
}

// Routine Description:
// - Checks if a char is a lead byte for a given code page.
// Arguments:
Expand Down
2 changes: 0 additions & 2 deletions src/host/dbcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Revision History:

bool CheckBisectStringA(_In_reads_bytes_(cbBuf) PCHAR pchBuf, _In_ DWORD cbBuf, const CPINFO* const pCPInfo);

DWORD UnicodeRasterFontCellMungeOnRead(const std::span<CHAR_INFO> buffer);

bool IsDBCSLeadByteConsole(const CHAR ch, const CPINFO* const pCPInfo);

BYTE CodePageToCharSet(const UINT uiCodePage);
Expand Down
73 changes: 2 additions & 71 deletions src/host/directio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,56 +413,6 @@ CATCH_RETURN();
CATCH_RETURN();
}

[[nodiscard]] static std::vector<CHAR_INFO> _ConvertCellsToMungedW(std::span<CHAR_INFO> buffer, const Viewport& rectangle)
{
std::vector<CHAR_INFO> result;
result.reserve(buffer.size());

const auto size = rectangle.Dimensions();
auto bufferIter = buffer.begin();

for (til::CoordType i = 0; i < size.height; i++)
{
for (til::CoordType j = 0; j < size.width; j++)
{
// Prepare a candidate charinfo on the output side copying the colors but not the lead/trail information.
auto candidate = *bufferIter;
WI_ClearAllFlags(candidate.Attributes, COMMON_LVB_SBCSDBCS);

// If the glyph we're given is full width, it needs to take two cells.
if (IsGlyphFullWidth(candidate.Char.UnicodeChar))
{
// If we're not on the final cell of the row...
if (j < size.width - 1)
{
// Mark that we're consuming two cells.
j++;

// Fill one cell with a copy of the color and character marked leading
WI_SetFlag(candidate.Attributes, COMMON_LVB_LEADING_BYTE);
result.push_back(candidate);

// Fill a second cell with a copy of the color marked trailing and a padding character.
WI_ClearFlag(candidate.Attributes, COMMON_LVB_LEADING_BYTE);
WI_SetFlag(candidate.Attributes, COMMON_LVB_TRAILING_BYTE);
}
else
{
// If we're on the final cell, this won't fit. Replace with a space.
candidate.Char.UnicodeChar = UNICODE_SPACE;
}
}

// Push our candidate in.
result.push_back(candidate);

// Advance to read the next item.
++bufferIter;
}
}
return result;
}

[[nodiscard]] HRESULT ReadConsoleOutputWImplHelper(const SCREEN_INFORMATION& context,
std::span<CHAR_INFO> targetBuffer,
const Viewport& requestRectangle,
Expand Down Expand Up @@ -547,16 +497,7 @@ CATCH_RETURN();

try
{
RETURN_IF_FAILED(ReadConsoleOutputWImplHelper(context, buffer, sourceRectangle, readRectangle));

if (!context.GetActiveBuffer().GetCurrentFont().IsTrueTypeFont())
{
// For compatibility reasons, we must maintain the behavior that munges the data if we are writing while a raster font is enabled.
// This can be removed when raster font support is removed.
UnicodeRasterFontCellMungeOnRead(buffer);
}

return S_OK;
return ReadConsoleOutputWImplHelper(context, buffer, sourceRectangle, readRectangle);
}
CATCH_RETURN();
}
Expand Down Expand Up @@ -684,17 +625,7 @@ CATCH_RETURN();
writer.BackupCursor();
}

if (!context.GetActiveBuffer().GetCurrentFont().IsTrueTypeFont())
{
// For compatibility reasons, we must maintain the behavior that munges the data if we are writing while a raster font is enabled.
// This can be removed when raster font support is removed.
auto translated = _ConvertCellsToMungedW(buffer, requestRectangle);
RETURN_IF_FAILED(WriteConsoleOutputWImplHelper(context, translated, requestRectangle.Width(), requestRectangle, writtenRectangle));
}
else
{
RETURN_IF_FAILED(WriteConsoleOutputWImplHelper(context, buffer, requestRectangle.Width(), requestRectangle, writtenRectangle));
}
RETURN_IF_FAILED(WriteConsoleOutputWImplHelper(context, buffer, requestRectangle.Width(), requestRectangle, writtenRectangle));

if (writer)
{
Expand Down
Loading