Get rid of XStringWP + few cleanings.

This commit is contained in:
Jief L 2020-03-31 18:59:35 +03:00
parent 8b806cf4e7
commit 23b45d569a
26 changed files with 264 additions and 188 deletions

View File

@ -102,6 +102,7 @@ extern "C" {
#include "../refit/screen.h" // for PauseForKey
#include "string.h"
#include "boot.h"
#include "plist.h"
//#include "PiBootMode.h"
#ifndef CLOVERAPPLICATION
#include "../refit/IO.h"
@ -750,18 +751,6 @@ struct Symbol {
typedef struct Symbol Symbol, *SymbolPtr;
typedef struct TagStruct {
UINTN type;
CHAR8 *string;
UINT8 *data;
UINTN dataLen;
UINTN offset;
struct TagStruct *tag;
struct TagStruct *tagNext;
} TagStruct, *TagPtr;
#pragma pack(push)
#pragma pack(1)
@ -2178,8 +2167,6 @@ ParseXML (
);
EFI_STATUS ParseSVGTheme(CONST CHAR8* buffer, TagPtr * dict);
//VOID RenderSVGfont(NSVGfont *fontSVG);
TagPtr

View File

@ -0,0 +1,27 @@
/*
* plist.h
*
* Created on: 31 Mar 2020
* Author: jief
*/
#ifndef PLATFORM_PLIST_H_
#define PLATFORM_PLIST_H_
typedef struct TagStruct {
UINTN type;
CHAR8 *string;
UINT8 *data;
UINTN dataLen;
UINTN offset;
struct TagStruct *tag;
struct TagStruct *tagNext;
} TagStruct, *TagPtr;
#endif /* PLATFORM_PLIST_H_ */

View File

@ -97,7 +97,7 @@ wchar_t * XStringW::forgetDataWithoutFreeing()
return ret;
}
const XStringW& XStringW::takeValueFrom(const wchar_t* S)
const XStringW& XStringW::takeValueFrom(const wchar_t* S, xsize count)
{
if ( !S ) {
// DebugLog(2, "takeValueFrom(const wchar_t* S) called with NULL. Use setEmpty()\n");
@ -105,11 +105,16 @@ const XStringW& XStringW::takeValueFrom(const wchar_t* S)
Init(0);
return *this;
}
Init(wcslen(S));
Init(count);
StrCpy(S);
return *this;
}
const XStringW& XStringW::takeValueFrom(const wchar_t* S)
{
return takeValueFrom(S, wcslen(S));
}
const XStringW& XStringW::takeValueFrom(const char* S)
{
xsize newLen = StrLenInWChar(S);
@ -530,7 +535,15 @@ const XStringW &XStringW::operator +=(const wchar_t *S)
// Functions
//-----------------------------------------------------------------------------
XStringW WPrintf(const char* format, ...)
XStringW operator"" _XSW ( const wchar_t* s, size_t len)
{
XStringW returnValue;
if ( len > MAX_XSIZE ) len = MAX_XSIZE;
returnValue.takeValueFrom(s, len);
return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization.
}
XStringW SWPrintf(const char* format, ...)
{
va_list va;
XStringW str;

View File

@ -14,15 +14,15 @@
#define LPATH_SEPARATOR L'\\'
extern UINTN XStringWGrowByDefault;
extern xsize XStringWGrowByDefault;
//extern void __GLOBAL__sub_I_XStringW();
class XStringW
{
protected:
wchar_t *m_data;
UINTN m_len;
UINTN m_allocatedSize;
xsize m_len;
xsize m_allocatedSize;
// convenience method. Did it this way to avoid #define in header. They can have an impact on other headers
xsize min(xsize x1, xsize x2) const { if ( x1 < x2 ) return x1; return x2; }
@ -38,18 +38,18 @@ protected:
wchar_t* _data(xisize i) const { if ( i<0 ) panic("wchar_t* data(xisize i) -> i < 0"); if ( (xsize)i >= m_allocatedSize ) panic("wchar_t* data(xisize i) -> i >= m_allocatedSize"); return m_data+i; }
public:
void Init(UINTN aSize=0);
void Init(xsize aSize=0);
XStringW();
XStringW(const XStringW &aString);
// XStringW(const wchar_t *);
// XStringW(const wchar_t* S, UINTN count);
// XStringW(const wchar_t* S, xsize count);
// XStringW(const wchar_t);
// XStringW(const char*);
~XStringW();
protected:
wchar_t *CheckSize(UINTN nNewSize, UINTN nGrowBy = XStringWGrowByDefault);
wchar_t *CheckSize(xsize nNewSize, xsize nGrowBy = XStringWGrowByDefault);
public:
const wchar_t* wc_str() const { return m_data; } // equivalent as std::string
@ -60,10 +60,10 @@ public:
wchar_t* dataSized(xisize i, xsize sizeMin, xsize nGrowBy=XStringWGrowByDefault) { if ( i<0 ) panic("wchar_t* dataSized(xisize i, xsize sizeMin, xsize nGrowBy) -> i < 0"); CheckSize((xsize)i+sizeMin, nGrowBy); return _data(i); }
wchar_t* forgetDataWithoutFreeing();
UINTN length() const { return m_len; }
UINTN size() const { return m_len; }
UINTN allocatedSize() const { return m_allocatedSize; }
void SetLength(UINTN len);
xsize length() const { return m_len; }
xsize size() const { return m_len; }
xsize allocatedSize() const { return m_allocatedSize; }
void SetLength(xsize len);
const wchar_t* s() { return m_data; }
/* Empty ? */
@ -80,7 +80,7 @@ public:
#endif
int ToInt() const;
UINTN ToUInt() const;
xsize ToUInt() const;
// XString mbs() const;
@ -105,14 +105,14 @@ public:
void SetNull() { SetLength(0); };
void StrnCpy(const wchar_t *buf, UINTN len);
void StrnCpy(const wchar_t *buf, xsize len);
void StrCpy(const wchar_t *buf);
void StrnCat(const wchar_t *buf, UINTN len);
void StrnCat(const wchar_t *buf, xsize len);
void StrCat(const wchar_t *buf);
void StrCat(const XStringW &uneXStringW);
void Delete(UINTN pos, UINTN count=1);
void Delete(xsize pos, xsize count=1);
void Insert(UINTN pos, const XStringW& Str);
void Insert(xsize pos, const XStringW& Str);
void vSPrintf(const char* format, va_list va);
@ -128,23 +128,24 @@ public:
// const XStringW &operator =(wchar_t);
const XStringW& takeValueFrom(const wchar_t* S);
const XStringW& takeValueFrom(const wchar_t* S, xsize count);
const XStringW& takeValueFrom(const char* S);
const XStringW &operator += (const XStringW &);
const XStringW &operator += (const wchar_t* S);
const XStringW &operator += (wchar_t);
XStringW SubString(UINTN pos, UINTN count) const;
UINTN IdxOf(wchar_t c, UINTN Pos = 0) const;
UINTN IdxOf(const XStringW& S, UINTN Pos = 0) const;
UINTN RIdxOf(const wchar_t c, UINTN Pos = MAX_XSIZE) const;
UINTN RIdxOf(const XStringW& S, UINTN Pos = MAX_XSIZE) const;
XStringW SubString(xsize pos, xsize count) const;
xsize IdxOf(wchar_t c, xsize Pos = 0) const;
xsize IdxOf(const XStringW& S, xsize Pos = 0) const;
xsize RIdxOf(const wchar_t c, xsize Pos = MAX_XSIZE) const;
xsize RIdxOf(const XStringW& S, xsize Pos = MAX_XSIZE) const;
void ToLower(bool FirstCharIsCap = false);
bool IsLetters() const;
bool IsLettersNoAccent() const;
bool IsDigits() const;
bool IsDigits(UINTN pos, UINTN count) const;
bool IsDigits(xsize pos, xsize count) const;
bool ExistIn(const XStringW &S) const { return IdxOf(S) != MAX_XSIZE; }
void Replace(wchar_t c1, wchar_t c2);
@ -154,19 +155,19 @@ public:
bool Equal(const wchar_t* S) const { return Compare(S) == 0; };
bool BeginingEqual(const wchar_t* S) const { return (memcmp(data(), S, wcslen(S)) == 0); }
bool SubStringEqual(UINTN Pos, const wchar_t* S) const { return (memcmp(data(Pos), S, wcslen(S)) == 0); }
bool SubStringEqual(xsize Pos, const wchar_t* S) const { return (memcmp(data(Pos), S, wcslen(S)) == 0); }
XStringW basename() const;
XStringW dirname() const;
// bool ReadFromBuf(const char *buf, UINTN *idx, UINTN count);
// bool WriteToBuf(char *buf, UINTN *idx, UINTN count) const;
// bool ReadFromBuf(const char *buf, xsize *idx, xsize count);
// bool WriteToBuf(char *buf, xsize *idx, xsize count) const;
// bool ReadFromFILE(FILE *fp);
// bool WriteToFILE(FILE *fp) const;
//
// bool ReadFromXBuffer(XRBuffer &unXBuffer); // Impossible de mettre le XBuffer en const car il y a une variable d'instance de XBuffer incrémentée par ReadFromXBuffer
// void CatToXBuffer(XBuffer *unXBuffer) const;
// void WriteToXBuffer(XBuffer *unXBuffer, UINTN *idx) const;
// void WriteToXBuffer(XBuffer *unXBuffer, xsize *idx) const;
public:
// + operator
@ -207,15 +208,18 @@ public:
};
//extern const XStringW NullXStringW;
extern const XStringW NullXStringW;
XStringW operator"" _XSW ( const wchar_t* s, size_t len);
#ifndef _MSC_VER
XStringW WPrintf(const char* format, ...) __attribute__((__format__(__printf__, 1, 2)));
XStringW SWPrintf(const char* format, ...) __attribute__((__format__(__printf__, 1, 2)));
#else
XStringW WPrintf(const char* format, ...);
XStringW SWPrintf(const char* format, ...);
#endif // !__MSC_VER
XStringW SubString(const wchar_t *S, UINTN pos, UINTN count);
XStringW SubString(const wchar_t *S, xsize pos, xsize count);
XStringW CleanCtrl(const XStringW &S);

View File

@ -42,7 +42,7 @@ void XStringWArray::AddStrings(const wchar_t *Val1, ...)
va_end(va);
}
XStringW XStringWArray::ConcatAll(XStringW Separator, XStringW Prefix, XStringW Suffix) const
XStringW XStringWArray::ConcatAll(const XStringW& Separator, const XStringW& Prefix, const XStringW& Suffix) const
{
xsize i;
XStringW s;

View File

@ -28,7 +28,7 @@ class XStringWArray : public XStringWArraySuper
bool IsNull() const { return size() == 0 ; }
bool NotNull() const { return size() > 0 ; }
XStringW ConcatAll(XStringW Separator = XStringWP(L", "), XStringW Prefix = XStringWP(L""), XStringW Suffix = XStringWP(L"")) const;
XStringW ConcatAll(const XStringW& Separator = L", "_XSW, const XStringW& Prefix = NullXStringW, const XStringW& Suffix = NullXStringW) const;
bool Equal(const XStringWArray &aStrings) const;
bool operator ==(const XStringWArray &aXStrings) const { return Equal(aXStrings); }
@ -50,6 +50,6 @@ class XStringWArray : public XStringWArraySuper
};
extern const XStringWArray NullXStringws;
XStringWArray Split(const XStringW &S, const XStringW &Separator = XStringWP(L", "));
XStringWArray Split(const XStringW &S, const XStringW &Separator = L", "_XSW);
#endif

View File

@ -1,55 +1,55 @@
//*************************************************************************************************
//*************************************************************************************************
////*************************************************************************************************
////*************************************************************************************************
////
//// STRING
////
//// Developed by jief666, from 1997.
////
////*************************************************************************************************
////*************************************************************************************************
//
// STRING
//
// Developed by jief666, from 1997.
//#if !defined(__XStringW_CPP__)
//#define __XStringW_CPP__
//
//*************************************************************************************************
//*************************************************************************************************
#if !defined(__XStringW_CPP__)
#define __XStringW_CPP__
#if 0
#define DBG(...) DebugLog(2, __VA_ARGS__)
#else
#define DBG(...)
#endif
#include "XToolsCommon.h"
#include "XStringWP.h"
#include "../../Include/Library/printf_lite.h"
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Constructor
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
XStringWP::XStringWP(const wchar_t *S)
{
if ( !S ) {
// DebugLog(2, "XStringWP(const wchar_t *S) called with NULL. Use setEmpty()\n");
// panic();
Init(0);
} else {
DBG("Constructor(const wchar_t *S) : %ls, StrLen(S)=%d\n", S, StrLen(S));
Init(wcslen(S));
StrCpy(S);
}
}
XStringWP::XStringWP(const char* S)
{
DBG("Constructor(const char* S)\n");
xsize newLen = StrLenInWChar(S);
Init(newLen);
utf8ToWChar(m_data, m_allocatedSize+1, S); // m_size doesn't count the NULL terminator
SetLength(newLen);
}
#endif
//#if 0
//#define DBG(...) DebugLog(2, __VA_ARGS__)
//#else
//#define DBG(...)
//#endif
//
//#include "XToolsCommon.h"
//#include "XStringWP.h"
//
//#include "../../Include/Library/printf_lite.h"
//
//
////xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//// Constructor
////xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//
//
//XStringWP::XStringWP(const wchar_t *S)
//{
// if ( !S ) {
//// DebugLog(2, "XStringWP(const wchar_t *S) called with NULL. Use setEmpty()\n");
//// panic();
// Init(0);
// } else {
// DBG("Constructor(const wchar_t *S) : %ls, StrLen(S)=%d\n", S, StrLen(S));
// Init(wcslen(S));
// StrCpy(S);
// }
//}
//
//XStringWP::XStringWP(const char* S)
//{
// DBG("Constructor(const char* S)\n");
// xsize newLen = StrLenInWChar(S);
// Init(newLen);
// utf8ToWChar(m_data, m_allocatedSize+1, S); // m_size doesn't count the NULL terminator
// SetLength(newLen);
//}
//
//
//#endif

View File

@ -1,32 +1,32 @@
//*************************************************************************************************
//*************************************************************************************************
////*************************************************************************************************
////*************************************************************************************************
////
//// STRING
////
////*************************************************************************************************
////*************************************************************************************************
//
// STRING
//#if !defined(__XStringWP_H__)
//#define __XStringWP_H__
//
//*************************************************************************************************
//*************************************************************************************************
#if !defined(__XStringWP_H__)
#define __XStringWP_H__
#include "XStringWP.h"
#include "XStringW.h"
#include "XToolsCommon.h"
#include "utf8Conversion.h"
#define XStringWP_super XStringW
class XStringWP : public XStringWP_super
{
protected:
// wchar_t *m_data;
public:
XStringWP() : XStringWP_super() {};
XStringWP(const wchar_t *);
XStringWP(const char*);
/* XStringWP(const char*, ...); // Cannot define this ctor although it would be handy. Problem is confusion with XStringWP(const char*) as ... can mean 0 arg. */
};
#endif
//#include "XStringWP.h"
//#include "XStringW.h"
//
//#include "XToolsCommon.h"
//#include "utf8Conversion.h"
//
//#define XStringWP_super XStringW
//class XStringWP : public XStringWP_super
//{
//protected:
//// wchar_t *m_data;
//
//public:
// XStringWP() : XStringWP_super() {};
// XStringWP(const wchar_t *);
// XStringWP(const char*);
// /* XStringWP(const char*, ...); // Cannot define this ctor although it would be handy. Problem is confusion with XStringWP(const char*) as ... can mean 0 arg. */
//
//};
//
//#endif

View File

@ -1,6 +1,6 @@
#include <Platform.h>
#include "../cpp_foundation/XStringWArray.h"
#include "../cpp_foundation/XStringWP.h"
#include "../cpp_foundation/XStringW.h"
int XStringWArray_tests()
{
@ -13,20 +13,20 @@ int XStringWArray_tests()
if ( !array1.IsNull() ) return 1;
array1.Add(XStringWP(L"1"));
array1.Add(L"1"_XSW);
if ( array1.IsNull() ) return 2;
array1.Add(XStringWP(L"2"));
array1.Add(L"2"_XSW);
if ( array1[0] != L"1" ) return 3;
if ( array1[1] != L"2" ) return 4;
if ( !array1.Contains(XStringWP(L"2")) ) return 5;
if ( !array1.Contains(L"2"_XSW) ) return 5;
// Test == and !=
{
XStringWArray array1bis;
array1bis.Add(XStringWP(L"1"));
array1bis.Add(XStringWP(L"2"));
array1bis.Add(L"1"_XSW);
array1bis.Add(L"2"_XSW);
if ( !(array1 == array1bis) ) return 10;
if ( array1 != array1bis ) return 11;
@ -34,19 +34,19 @@ int XStringWArray_tests()
// Test concat and Split
{
XStringW c = array1.ConcatAll(XStringWP(L", "), XStringWP(L"^"), XStringWP(L"$"));
XStringW c = array1.ConcatAll(L", "_XSW, L"^"_XSW, L"$"_XSW);
if ( c != L"^1, 2$" ) return 1;
// Split doesn't handle prefix and suffix yet.
c = array1.ConcatAll(XStringWP(L", "));
c = array1.ConcatAll(L", "_XSW);
XStringWArray array1bis = Split(c);
if ( array1 != array1bis ) return 20;
}
XStringWArray array2;
array2.Add(XStringWP(L"2"));
array2.Add(XStringWP(L"1"));
array2.Add(L"2"_XSW);
array2.Add(L"1"_XSW);
if ( array2[0] != L"2" ) return 30;
if ( array2[1] != L"1" ) return 31;
@ -55,13 +55,13 @@ int XStringWArray_tests()
if ( array1 == array2 ) return 40; // Array != because order is different
if ( !array1.Same(array2) ) return 41; // Arrays are the same
array1.AddNoNull(XStringWP(L"3"));
array1.AddNoNull(L"3"_XSW);
if ( array1.size() != 3 ) return 50;
array1.AddNoNull(XStringWP(L""));
array1.AddNoNull(L""_XSW);
if ( array1.size() != 3 ) return 51;
array1.AddEvenNull(XStringW());
if ( array1.size() != 4 ) return 52;
array1.AddID(XStringWP(L"2"));
array1.AddID(L"2"_XSW);
if ( array1.size() != 4 ) return 53;

View File

@ -11,6 +11,9 @@ int XStringW_tests()
{
#ifdef JIEF_DEBUG
XStringW a = L"toto"_XSW;
// DebugLog(2, "XStringW_tests -> Enter\n");
#endif

View File

@ -3,13 +3,22 @@
#include "../cpp_foundation/utf8Conversion.h"
#include "global_test.h"
template<int m_size>
class Xtest
{
char m_data[m_size];
public:
int size() { return m_size; }
};
int XString_tests()
{
XString a = "toto"_XS;
// Xtest<5> b;
// int bs = b.size();
#ifdef JIEF_DEBUG
#endif

View File

@ -489,7 +489,7 @@ BOOLEAN AskUserForFilePathFromDir(IN CHAR16 *Title OPTIONAL, IN REFIT_VOLUME *Vo
// 0, NULL, NULL, FALSE, FALSE, 0, 0, 0, 0,
// { 0, 0, 0, 0 }, NULL};
#if USE_XTHEME
STATIC REFIT_MENU_SCREEN InitialMenu(0, XStringWP(L"Please Select File..."), XStringW());
STATIC REFIT_MENU_SCREEN InitialMenu(0, L"Please Select File..."_XSW, XStringW());
#else
STATIC REFIT_MENU_SCREEN InitialMenu(0, L"Please Select File...", NULL);
#endif
@ -517,7 +517,7 @@ BOOLEAN AskUserForFilePathFromVolumes(IN CHAR16 *Title OPTIONAL, OUT EFI_DEVICE_
((Volume->DevicePathString == NULL) && (Volume->VolName == NULL))) {
continue;
}
REFIT_SIMPLE_MENU_ENTRY_TAG *Entry = new REFIT_SIMPLE_MENU_ENTRY_TAG(XStringWP((Volume->VolName == NULL) ? Volume->DevicePathString : Volume->VolName), TAG_OFFSET + Index, MENU_EXIT_ENTER);
REFIT_SIMPLE_MENU_ENTRY_TAG *Entry = new REFIT_SIMPLE_MENU_ENTRY_TAG(SWPrintf("%ls", (Volume->VolName == NULL) ? Volume->DevicePathString : Volume->VolName), TAG_OFFSET + Index, MENU_EXIT_ENTER);
// Entry = Entries[Count++] = EntryPtr++;
// Entry->Title = (Volume->VolName == NULL) ? Volume->DevicePathString : Volume->VolName;
// Entry->Tag = TAG_OFFSET + Index;

View File

@ -197,7 +197,7 @@ BOOLEAN AddLegacyEntry(IN CONST CHAR16 *FullTitle, IN CONST CHAR16 *LoaderTitle,
// SubScreen = (__typeof__(SubScreen))AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
SubScreen = new REFIT_MENU_SCREEN();
#if USE_XTHEME
SubScreen->Title = XStringWP(L"Boot Options for ") + LoaderTitle + L" on " + VolDesc;
SubScreen->Title.SPrintf("Boot Options for %ls on %ls", LoaderTitle, VolDesc);
#else
SubScreen->Title = PoolPrint(L"Boot Options for %s on %s", LoaderTitle, VolDesc);
#endif

View File

@ -783,7 +783,7 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry)
// SubScreen = (__typeof__(SubScreen))AllocateZeroPool(sizeof(REFIT_MENU_SCREEN));
SubScreen = new REFIT_MENU_SCREEN;
#if USE_XTHEME
SubScreen->Title = XStringWP("Options for ") + Entry->Title.s() + L" on " + Entry->VolName;
SubScreen->Title.SPrintf("Options for %ls on %ls", Entry->Title.wc_str(), Entry->VolName);
#else
//very old mistake!!!
SubScreen->Title = PoolPrint(L"Options for %s on %s", Entry->Title.s(), Entry->VolName);
@ -798,7 +798,7 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry)
SubScreen->AddMenuInfoLine(FileDevicePathToStr(Entry->DevicePath));
Guid = FindGPTPartitionGuidInDevicePath(Volume->DevicePath);
if (Guid) {
SubScreen->AddMenuInfoLine(WPrintf("UUID: %s", strguid(Guid)).wc_str());
SubScreen->AddMenuInfoLine(SWPrintf("UUID: %s", strguid(Guid)).wc_str());
}
SubScreen->AddMenuInfoLine(PoolPrint(L"Options: %s", Entry->LoadOptions));
// loader-specific submenu entries
@ -2025,7 +2025,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
REFIT_MENU_SCREEN *SubScreen = new REFIT_MENU_SCREEN;
if (SubScreen) {
#if USE_XTHEME
SubScreen->Title = XStringWP("Boot Options for ") + ((Custom->Title != NULL) ? Custom->Title : CustomPath) + L" on " + Entry->VolName;
SubScreen->Title.SPrintf("Boot Options for %ls on %ls", (Custom->Title != NULL) ? Custom->Title : CustomPath, Entry->VolName);
#else
SubScreen->Title = PoolPrint(L"Boot Options for %s on %s", (Custom->Title != NULL) ? Custom->Title : CustomPath, Entry->VolName);
#endif
@ -2035,10 +2035,10 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex,
SubScreen->ID = Custom->Type + 20;
SubScreen->AnimeRun = SubScreen->GetAnime();
VolumeSize = RShiftU64(MultU64x32(Volume->BlockIO->Media->LastBlock, Volume->BlockIO->Media->BlockSize), 20);
SubScreen->AddMenuInfoLine(XStringWP(L"Volume size: ") + WPrintf("%lldMb", VolumeSize));
SubScreen->AddMenuInfoLine(SWPrintf("Volume size: %lldMb", VolumeSize));
SubScreen->AddMenuInfoLine(FileDevicePathToStr(Entry->DevicePath));
if (Guid) {
SubScreen->AddMenuInfoLine(WPrintf("UUID: %s", strguid(Guid)).wc_str());
SubScreen->AddMenuInfoLine(SWPrintf("UUID: %s", strguid(Guid)).wc_str());
}
SubScreen->AddMenuInfoLine(PoolPrint(L"Options: %s", Entry->LoadOptions));
DBG("Create sub entries\n");

View File

@ -12,7 +12,7 @@
#define TEST_FONT 0
#define TEST_DITHER 0
#include "VectorGraphics.h"
#include "../Platform/Platform.h"
@ -747,8 +747,9 @@ EG_IMAGE * LoadSvgFrame(INTN i)
//textType = 0-help 1-message 2-menu 3-test
//return text width in pixels
#if USE_XTHEME
INTN renderSVGtext(XImage& TextBufferXY, INTN posX, INTN posY, INTN textType, XStringW string, UINTN Cursor)
INTN renderSVGtext(XImage* TextBufferXY_ptr, INTN posX, INTN posY, INTN textType, const XStringW& string, UINTN Cursor)
{
XImage& TextBufferXY = *TextBufferXY_ptr;
INTN Width;
UINTN i;
UINTN len;
@ -1085,7 +1086,7 @@ VOID testSVG()
FreePool(FileData);
// Scale = Height / fontSVG->unitsPerEm;
#if USE_XTHEME
renderSVGtext(TextBufferXY, 0, 0, 3, XStringW().takeValueFrom("Clover Кловер"), 1);
renderSVGtext(&TextBufferXY, 0, 0, 3, XStringW().takeValueFrom("Clover Кловер"), 1);
#else
renderSVGtext(TextBufferXY, 0, 0, 3, L"Clover Кловер", 1);
#endif

View File

@ -0,0 +1,26 @@
/*
* VectorGraphics.h
*
* Created on: 31 Mar 2020
* Author: jief
*/
#ifndef LIBEG_VECTORGRAPHICS_H_
#define LIBEG_VECTORGRAPHICS_H_
#include "../cpp_foundation/XStringW.h"
#include "../Platform/plist.h"
#include "XImage.h"
EFI_STATUS ParseSVGTheme(CONST CHAR8* buffer, TagPtr * dict);
#if USE_XTHEME
INTN renderSVGtext(XImage* TextBufferXY, INTN posX, INTN posY, INTN textType, const XStringW& string, UINTN Cursor);
#else
INTN renderSVGtext(EG_IMAGE* TextBufferXY, INTN posX, INTN posY, INTN textType, CONST CHAR16* text, UINTN Cursor);
#endif
VOID testSVG(VOID);
#endif /* LIBEG_VECTORGRAPHICS_H_ */

View File

@ -167,6 +167,11 @@ EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetPixelPtr(UINTN x, UINTN y)
return &PixelData[x + y * Width];
}
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* XImage::GetPixelPtr(UINTN x, UINTN y) const
{
return &PixelData[x + y * Width];
}
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& XImage::GetPixel(UINTN x, UINTN y) const
{
return PixelData[x + y * Width];
@ -544,12 +549,12 @@ void XImage::Draw(INTN x, INTN y, float scale, bool Opaque)
*/
EFI_STATUS XImage::LoadXImage(EFI_FILE *BaseDir, const char* IconName)
{
return LoadXImage(BaseDir, XStringWP(IconName));
return LoadXImage(BaseDir, XStringW().takeValueFrom(IconName));
}
EFI_STATUS XImage::LoadXImage(EFI_FILE *BaseDir, const wchar_t* LIconName)
{
return LoadXImage(BaseDir, XStringWP(LIconName));
return LoadXImage(BaseDir, XStringW().takeValueFrom(LIconName));
}
//dont call this procedure for SVG theme BaseDir == NULL?
EFI_STATUS XImage::LoadXImage(EFI_FILE *BaseDir, const XStringW& IconName)

View File

@ -69,6 +69,7 @@ public:
const XArray<EFI_GRAPHICS_OUTPUT_BLT_PIXEL>& GetData() const;
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& GetPixel(UINTN x, UINTN y) const;
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetPixelPtr(UINTN x, UINTN y) const ;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL* GetPixelPtr(UINTN x, UINTN y);
UINTN GetWidth() const;
UINTN GetHeight() const;

View File

@ -586,7 +586,7 @@ void XTheme::FillByDir() //assume ThemeDir is defined by InitTheme() procedure
for (INTN i = 0; i <= BUILTIN_CHECKBOX_CHECKED; ++i) {
Icon NewIcon(i); //initialize with embedded but further replace by loaded
NewIcon.Image.LoadXImage(ThemeDir, IconsNames[i]);
NewIcon.ImageNight.LoadXImage(ThemeDir, XStringWP(IconsNames[i]) + XStringWP("_night"));
NewIcon.ImageNight.LoadXImage(ThemeDir, SWPrintf("%s_night", IconsNames[i]));
Icons.AddCopy(NewIcon);
}

View File

@ -509,7 +509,6 @@ VOID egTakeImage(IN EG_IMAGE *Image, INTN ScreenPosX, INTN ScreenPosY,
EFI_STATUS egScreenShot(VOID);
VOID testSVG(VOID);
#endif /* __LIBEG_LIBEG_H__ */

View File

@ -182,11 +182,9 @@ EG_IMAGE * egDecodePNG(IN UINT8 *FileData, IN UINTN FileDataLength, IN BOOLEAN W
//VOID egEncodeBMP(IN EG_IMAGE *Image, OUT UINT8 **FileData, OUT UINTN *FileDataLength);
#if USE_XTHEME
INTN renderSVGtext(XImage& TextBufferXY, INTN posX, INTN posY, INTN textType, XStringW string, UINTN Cursor);
INTN egRenderText(IN XStringW& Text, IN XImage& CompImage,
INTN egRenderText(IN const XStringW& Text, OUT XImage* CompImage,
IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType);
#else
INTN renderSVGtext(EG_IMAGE* TextBufferXY, INTN posX, INTN posY, INTN textType, CONST CHAR16* text, UINTN Cursor);
INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType);
#endif

View File

@ -386,7 +386,7 @@ VOID egInitScreen(IN BOOLEAN SetMaxResolution)
// if it not the first run, just restore resolution
if (egScreenWidth != 0 && egScreenHeight != 0) {
// Resolution = PoolPrint(L"%dx%d",egScreenWidth,egScreenHeight);
XStringW Resolution = WPrintf("%llux%llu", egScreenWidth, egScreenHeight);
XStringW Resolution = SWPrintf("%llux%llu", egScreenWidth, egScreenHeight);
// if (Resolution) { //no sense
Status = egSetScreenResolution(Resolution.wc_str());
// FreePool(Resolution);
@ -648,12 +648,12 @@ EFI_STATUS egScreenShot(VOID)
return EFI_NOT_READY;
}
//save file with a first unoccupied name
XStringWP CommonName(L"EFI\\CLOVER\\misc\\screenshot");
// XStringW CommonName(L"EFI\\CLOVER\\misc\\screenshot"_XSW);
for (UINTN Index = 0; Index < 60; Index++) {
// ScreenshotName = PoolPrint(L"%a%d.png", ScreenShotName, Index);
XStringW Name = CommonName + WPrintf("%lld", Index) + L".png";
if (!FileExists(SelfRootDir, Name.data())) {
Status = egSaveFile(SelfRootDir, Name.data(), FileData, FileDataLength);
XStringW Name = SWPrintf("EFI\\CLOVER\\misc\\screenshot%lld.png", Index);
if (!FileExists(SelfRootDir, Name.wc_str())) {
Status = egSaveFile(SelfRootDir, Name.wc_str(), FileData, FileDataLength);
if (!EFI_ERROR(Status)) {
break;
}

View File

@ -37,6 +37,7 @@
#include "libegint.h"
#include "nanosvg.h"
#include "VectorGraphics.h"
//#include "egemb_font.h"
//#define FONT_CELL_WIDTH (7)
@ -312,13 +313,16 @@ INTN GetEmpty(EG_PIXEL *Ptr, EG_PIXEL *FirstPixel, INTN MaxWidth, INTN Step, INT
}
#if USE_XTHEME
INTN egRenderText(IN XStringW& Text, IN XImage& CompImage,
INTN egRenderText(IN const XStringW& Text, OUT XImage* CompImage_ptr,
IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType)
#else
INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage,
IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType)
#endif
{
#if USE_XTHEME
XImage& CompImage = *CompImage_ptr;
#endif
EG_PIXEL *BufferPtr;
EG_PIXEL *FontPixelData;
EG_PIXEL *FirstPixelBuf;
@ -335,7 +339,7 @@ INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage,
#if USE_XTHEME
INTN ScaledWidth = (INTN)(ThemeX.CharWidth * ThemeX.Scale);
if (ThemeX.TypeSVG) {
return renderSVGtext(CompImage, PosX, PosY, textType, Text, Cursor);
return renderSVGtext(&CompImage, PosX, PosY, textType, Text, Cursor);
}
#else
INTN ScaledWidth = (INTN)(GlobalConfig.CharWidth * GlobalConfig.Scale);

View File

@ -2323,10 +2323,9 @@ RefitMain (IN EFI_HANDLE ImageHandle,
// DBG("DBG: messages\n");
if (!GlobalConfig.NoEarlyProgress && !GlobalConfig.FastBoot && GlobalConfig.Timeout>0) {
#if USE_XTHEME
XStringW Message = XStringWP(" Welcome to Clover ") + gFirmwareRevision;
XStringW Message = SWPrintf(" Welcome to Clover %ls ", gFirmwareRevision);
DrawTextXY(Message, (UGAWidth >> 1), UGAHeight >> 1, X_IS_CENTER);
Message = XStringWP("... testing hardware ...");
DrawTextXY(Message, (UGAWidth >> 1), (UGAHeight >> 1) + 20, X_IS_CENTER);
DrawTextXY(L"... testing hardware ..."_XSW, (UGAWidth >> 1), (UGAHeight >> 1) + 20, X_IS_CENTER);
#else
FirstMessage = PoolPrint(L" Welcome to Clover %s ", gFirmwareRevision);
DrawTextXY(FirstMessage, (UGAWidth >> 1), UGAHeight >> 1, X_IS_CENTER);
@ -2395,7 +2394,7 @@ RefitMain (IN EFI_HANDLE ImageHandle,
if (!GlobalConfig.NoEarlyProgress && !GlobalConfig.FastBoot && GlobalConfig.Timeout>0) {
#if USE_XTHEME
XStringW Message = XStringWP("... user settings ...");
XStringW Message = SWPrintf("... user settings ...");
DrawTextXY(Message, (UGAWidth >> 1), (UGAHeight >> 1) + 20, X_IS_CENTER);
#else
FirstMessage = PoolPrint(L"... user settings ...");
@ -2472,7 +2471,7 @@ RefitMain (IN EFI_HANDLE ImageHandle,
if (!GlobalConfig.NoEarlyProgress && !GlobalConfig.FastBoot && GlobalConfig.Timeout>0) {
#if USE_XTHEME
XStringW Message = XStringWP("... scan entries ...");
XStringW Message = SWPrintf("... scan entries ...");
DrawTextXY(Message, (UGAWidth >> 1), (UGAHeight >> 1) + 20, X_IS_CENTER);
#else
FirstMessage = PoolPrint(L"... scan entries ...");
@ -2665,7 +2664,7 @@ RefitMain (IN EFI_HANDLE ImageHandle,
// font already changed and this message very quirky, clear line here
if (!GlobalConfig.NoEarlyProgress && !GlobalConfig.FastBoot && GlobalConfig.Timeout>0) {
#if USE_XTHEME
XStringW Message = XStringWP(" ");
XStringW Message = L" "_XSW;
DrawTextXY(Message, (UGAWidth >> 1), (UGAHeight >> 1) + 20, X_IS_CENTER);
#else
DrawTextXY(L" ", (UGAWidth >> 1), (UGAHeight >> 1) + 20, X_IS_CENTER);

View File

@ -215,11 +215,11 @@ BOOLEAN mGuiReady = FALSE;
//REFIT_MENU_ITEM_OPTIONS(CONST CHAR16 *Title_, UINTN Row_, CHAR16 ShortcutDigit_, CHAR16 ShortcutLetter_, ACTION AtClick_)
REFIT_MENU_ITEM_OPTIONS MenuEntryOptions (XStringWP("Options"), 1, 0, 'O', ActionEnter);
REFIT_MENU_ITEM_ABOUT MenuEntryAbout (XStringWP("About Clover"), 1, 0, 'A', ActionEnter);
REFIT_MENU_ITEM_RESET MenuEntryReset (XStringWP("Restart Computer"), 1, 0, 'R', ActionSelect);
REFIT_MENU_ITEM_SHUTDOWN MenuEntryShutdown(XStringWP("Exit Clover"), 1, 0, 'U', ActionSelect);
REFIT_MENU_ITEM_RETURN MenuEntryReturn (XStringWP("Return"), 0, 0, 0, ActionEnter);
REFIT_MENU_ITEM_OPTIONS MenuEntryOptions (L"Options"_XSW, 1, 0, 'O', ActionEnter);
REFIT_MENU_ITEM_ABOUT MenuEntryAbout (L"About Clover"_XSW, 1, 0, 'A', ActionEnter);
REFIT_MENU_ITEM_RESET MenuEntryReset (L"Restart Computer"_XSW, 1, 0, 'R', ActionSelect);
REFIT_MENU_ITEM_SHUTDOWN MenuEntryShutdown(L"Exit Clover"_XSW, 1, 0, 'U', ActionSelect);
REFIT_MENU_ITEM_RETURN MenuEntryReturn (L"Return"_XSW, 0, 0, 0, ActionEnter);
@ -2611,7 +2611,7 @@ UINTN REFIT_MENU_SCREEN::RunGenericMenu(IN MENU_STYLE_FUNC StyleFunc, IN OUT INT
if (HaveTimeout) {
#if USE_XTHEME
//TimeoutMessage = PoolPrint(L"%s in %d seconds", TimeoutText.data(), TimeoutCountdown);
XStringW TOMessage = TimeoutText + L" in " + WPrintf("%lld", TimeoutCountdown) + L" seconds";
XStringW TOMessage = SWPrintf("%ls in %lld seconds", TimeoutText.wc_str(), TimeoutCountdown);
((*this).*(StyleFunc))(MENU_FUNCTION_PAINT_TIMEOUT, TOMessage.data());
// FreePool(TimeoutMessage);
#else
@ -3131,7 +3131,7 @@ VOID REFIT_MENU_SCREEN::TextMenuStyle(IN UINTN Function, IN CONST CHAR16 *ParamT
#if USE_XTHEME
INTN DrawTextXY(IN XStringW& Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAlign)
INTN DrawTextXY(IN const XStringW& Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAlign)
{
INTN TextWidth = 0;
INTN XText = 0;
@ -3175,7 +3175,7 @@ INTN DrawTextXY(IN XStringW& Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAlign)
TextBufferXY.Fill(&MenuBackgroundPixel);
// render the text
TextWidth = egRenderText(Text, TextBufferXY, 0, 0, 0xFFFF, TextXYStyle);
TextWidth = egRenderText(Text, &TextBufferXY, 0, 0, 0xFFFF, TextXYStyle);
if (XAlign != X_IS_LEFT) {
// shift 64 is prohibited
@ -3360,11 +3360,11 @@ VOID DrawMenuText(IN XStringW& Text, IN INTN SelectedWidth, IN INTN XPos, IN INT
// render the text
if (ThemeX.TypeSVG) {
//clovy - text veltically centred on Height
egRenderText(Text, TextBufferX, 0,
egRenderText(Text, &TextBufferX, 0,
(INTN)((TextHeight - (textFace[TextStyle].size * ThemeX.Scale)) / 2),
Cursor, TextStyle);
} else {
egRenderText(Text, TextBufferX, TEXT_XMARGIN, TEXT_YMARGIN, Cursor, TextStyle);
egRenderText(Text, &TextBufferX, TEXT_XMARGIN, TEXT_YMARGIN, Cursor, TextStyle);
}
TextBufferX.Draw((INTN)XPos, (INTN)YPos);
}

View File

@ -10,8 +10,8 @@
VOID OptionsMenu(OUT REFIT_ABSTRACT_MENU_ENTRY **ChosenEntry);
VOID FreeScrollBar(VOID);
#if USE_XTHEME
INTN DrawTextXY(IN XStringW& Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAlign);
VOID DrawMenuText(IN XStringW& Text, IN INTN SelectedWidth, IN INTN XPos, IN INTN YPos, IN INTN Cursor);
INTN DrawTextXY(IN const XStringW& Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAlign);
VOID DrawMenuText(IN const XStringW& Text, IN INTN SelectedWidth, IN INTN XPos, IN INTN YPos, IN INTN Cursor);
#else
INTN DrawTextXY(IN CONST CHAR16 *Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAlign);
VOID DrawMenuText(IN CONST CHAR16 *Text, IN INTN SelectedWidth, IN INTN XPos, IN INTN YPos, IN INTN Cursor);