本文整理汇总了C++中UT_ByteBuf::truncate方法的典型用法代码示例。如果您正苦于以下问题:C++ UT_ByteBuf::truncate方法的具体用法?C++ UT_ByteBuf::truncate怎么用?C++ UT_ByteBuf::truncate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UT_ByteBuf
的用法示例。
在下文中一共展示了UT_ByteBuf::truncate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _loadStream
/**
* Code from Dom Lachowicz and/or Robert Staudinger.
*/
UT_Error ODi_Abi_Data::_loadStream (GsfInfile* oo,
const char* stream,
UT_ByteBuf& buf ) {
guint8 const *data = NULL;
size_t len = 0;
static const size_t BUF_SZ = 4096;
buf.truncate (0);
GsfInput * input = gsf_infile_child_by_name(oo, stream);
if (!input)
return UT_ERROR;
if (gsf_input_size (input) > 0) {
while ((len = gsf_input_remaining (input)) > 0) {
len = UT_MIN (len, BUF_SZ);
if (NULL == (data = gsf_input_read (input, len, NULL))) {
g_object_unref (G_OBJECT (input));
return UT_ERROR;
}
buf.append ((const UT_Byte *)data, len);
}
}
g_object_unref (G_OBJECT (input));
return UT_OK;
}
示例2: CreateBMPFile
//
// Creates a BITMAP file from a handle
//
static void CreateBMPFile(HWND hwnd, UT_ByteBuf & pBB, PBITMAPINFO pbi,
HBITMAP hBMP, HDC hDC)
{
BITMAPFILEHEADER hdr; // bitmap file-header
PBITMAPINFOHEADER pbih; // bitmap info-header
LPBYTE lpBits; // memory pointer
if (!hBMP) return;
pbih = (PBITMAPINFOHEADER) pbi;
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);
if (!lpBits) return;
// Retrieve the color table (RGBQUAD array) and the bits
// (array of palette indices) from the DIB.
if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi,
DIB_RGB_COLORS))
return;
hdr.bfType = 0x4d42; // 0x42 = "B" 0x4d = "M"
// Compute the size of the entire file.
hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) +
pbih->biSize + pbih->biClrUsed
* sizeof(RGBQUAD) + pbih->biSizeImage);
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
// Compute the offset to the array of color indices.
hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
pbih->biSize + pbih->biClrUsed
* sizeof (RGBQUAD);
pBB.truncate (0);
// Copy the BITMAPFILEHEADER into the .BMP file.
pBB.append ((const UT_Byte *)&hdr, sizeof(BITMAPFILEHEADER));
pBB.append ((const UT_Byte *)pbih, sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof (RGBQUAD));
// Copy the array of color indices into the .BMP file.
pBB.append ((const UT_Byte *)lpBits, (int) pbih->biSizeImage);
GlobalFree((HGLOBAL)lpBits);
}