YS SYSTEM FONT Library for Windows, MacOSX, and Linux (X-Window)

Updates
  2011/05/13 J



1. Tv
̃pbP[ẂAWindows, MacOSX, Linux (X-Window)ŋʂɗp\C++t
Hgrbg}bvWJR[h񋟂BAMacOSXpR[hŁÂ܂iOSp
ɎgƎvǁA܂ĂȂB

OpenGL̍ő̎_̂ЂƂAȂĂƂBtHg̊ǗƃO
tBbNX𕪗Ăf́AƂĂ͐񂯂ǁAv
OɂĂ݂ƁAƂɂȂł玚oĂƂɁA
Ȃ荢BwglUseFontBitmapƂg΁AAXL[͏o邯ǁA
oȂɁAWindowsɈˑĂ܂āANXvbgtH[OpenGL
̈Ӗ܂ȂBOpenGĹAƂŃvbgtH[
ɈˑĂ܂̂B͏\_ƌƎvB

ŁAAXL[R[hAvOɃtHgĂ
΃vbgtH[ɈˑȂȂ邩ĂƂŁAAXL[\
悤ɂR[hOɌJǁA͏oȂB

ɑΉ邽߂ɁAUnicodẽtHg̃f[^̃vÕpbP
[WɑgݍނȂĂƂpbP[W̃TCY剻Ă܂B
ႠAũvO𗘗pɂ́AtHg_E
[hĂāÃfBNgɒuĂvƂ悤Ȑďo
Ƃ͂ȂBāAvO_E[hƂAt@C{
SĂĂyłBɁAKvȃf[^t@ĆATCg
ړ]ŁAꏊ_E[hłȂȂĂ݂肷B

WindowsȂMacOSXȂLinuxȂVXeUnicodeɑΉtHg
Ă񂾂A𗘗pBÁAtHg̃rbg}bv
ɃANZXɂ́AꂼPCłĂł΂΂APIgȂȂȂ
ĂƂBoтɃvbgtH[ƂɈႤR[hĂ
܂ɂ\IB

Ȃ̂ŁAƂ肠AWindowsMac OSXLinux (X-Window)ŋʂɎgC++tH
grbg}bvWJR[h邱ƂɂBRZvǵAtHgƂw
łȂĂAw̑傫ŁAƂɂȒPȃR[hœǂ߂镶o
ƁB





2. wb_t@CA\[Xt@C
̃R[h𗘗pɂ́Ayssystemfont.hCN[hKvBȂ
ŁAyssystemfont.hCN[hpXʂfBNgɃRs[邩A
́Ayssystemfont.h̃fBNgɃCN[hpXǉĂKv
B

܂ACǔ`ɂ܂łƎvŁÂ܂܃\[Xt@C
srcfBNgɂ̂ŁAꂼA

    MacOSXp
        src/macosx/ysmacosxsystemfont.cpp
        src/macosx/ysmacosxsystemfont_objc.m

    Windowsp
        src/windows/yswin32systemfont.cpp

    Linuxp
        src/linux/ysunixsystemfont.cpp

ApAvP[VƈꏏɃRpCăNKvB





3. GcȎg
rbg}bvWJ邽߂ɁA̓ނ̃NXgB

    YsSystemFontCache
    YsSystemFontTextBitmap

YsSystemFontCachéAvbgtH[ˑ̃f[^inhO
tBbNXReLXgfBXvC|C^jŉB
āAtHgrbg}bvWJ@\B̃NX̊֐

    YsSystemFontCache::MakeSingleBitBitmap
    YsSystemFontCache::MakeRGBABitmap
    YsSystemFontCache::MakeGrayScaleAndAlphaBitmap

̂̂ЂƂgāAYsSystemFontTextBitmapɃrbg}bvWJ邱
ƂłBWJrbg}bv́AقƂǂ̂܂OpenGLglDrawPixels
glBitmapŕ`悷邱ƂłB(glDrawPixels(24rbg{)/pixelA
܂́A(8rbg{)/pixel̂ƂAglBitmap1rbg/sNẐƂ)

AYsSystemFontCache̐͌\dāA܂Arbg}bv̓WJ
\xBȂ̂ŁA܂x`悷Ƃ́A炩߃rbg
}bvWJĂǂBrbg}bvWJȂA
YsSystemFontCache͖ĂB

Ⴆ΁Â悤ɐrbg}bvɑ΂āA

    YsSystemFontCache fontCache;
    fontCache.RequestDefaultFontWithHeight(20);

    YsSystemFontTextBitmap bmp1,bmp2,bmp3;
    wchar_t yamakawa[]={0x5c71,0x5ddd,'\n','Y','a','m','a','k','a','w','a',0};
    wchar_t soji[]={0x7dcf,0x53f8,'\n','S','o','j','i',0};
    wchar_t greek[]={0x03b8,'=',0x03c0,0x03c9,0};

    fontCache.MakeRGBABitmap(bmp1,yamakawa,0xffffff,0,YSTRUE);
    fontCache.MakeSingleBitBitmap(bmp2,soji,YSTRUE);
    fontCache.MakeGrayScaleAndAlphaBitmap(bmp3,greek,0xff,0,YSTRUE);

OpenGL֐ŕ`悪\B

    glRasterPos2i(0,bmp1.Height()-1);
    glDrawPixels(bmp1.Width(),bmp1.Height(),GL_RGBA,GL_UNSIGNED_BYTE,bmp1.Bitmap());

    glColor3ub(0,255,0);
    glRasterPos2i(0,bmp1.Height()+bmp2.Height()-1);
    glBitmap(bmp2.Width(),bmp2.Height(),0,0,bmp2.Width(),0,bmp2.Bitmap());

    glRasterPos2i(0,bmp1.Height()+bmp2.Height()+bmp3.Height()-1);
    glDrawPixels(bmp3.Width(),bmp3.Height(),GL_LUMINANCE_ALPHA,GL_UNSIGNED_BYTE,bmp3.Bitmap());





4. ^CvANX

typedef enum {YSERR,YSOK} YSRESULT;
  sʂ\^CvB



typedef enum {YSFALSE,YSTRUE,YSTFUNKNOWN} YSBOOL;
  ^U\^CvB



YsSystemFontTextBitmapNX
  tHgWJʂێNXBYsSystemFontCacheNX
  tHgrbg}bvɕێB
  [o]
    inline YsSystemFontTextBitmap();
      ftHgRXgN^B

    inline ~YsSystemFontTextBitmap();
      ftHgfXgN^BYsSystemFontCacheNXrbg}bv
      ̃IuWFNgێĂꍇ́Arbg}bvgpĂ
      ԂB

    inline void CleanUp(void);
      gɂB

    inline unsigned int Width(void) const;
      sNZB

    inline unsigned int Height(void) const;
      csNZB

    inline unsigned int BytePerLine(void) const;
      񂠂̃oCgB

    inline unsigned int BitPerPixel(void) const;
      sNZ̃rbgB

    inline const unsigned char *Bitmap(void) const;
      rbg}bvf[^ԂB

    inline unsigned char *TransferBitmap(void) const;
      rbg}bvf[^̊Ǘ𑼂̃NXɈڊǂB

      IuWFNgrbg}bvf[^ێԂŁÅ֐s
      ƁArbg}bvf[^ւ̃|C^ԂāÃIuWFNgg͋
      ̃rbg}bvɂȂBiłȂꍇNULLԂBj

      ̊֐Ԃ|C^́AȌケ̃IuWFNg̊Ǘł͂ȂȂ
      ŁAfXgN^͂̃|C^wubNȂB
      Ȃ̂ŁÃrbg}bvsvɂȂƂAĂяodelete []
      gč폜KvB

      YsSystemFontTextBitmapNXgărbg}bvAʂ̃f[
      ^\Ƀrbg}bvǗƂÅ֐gƂŁArbg
      }bṽRs[ɂI[o[wbhłB



YsSystemFontCacheNX
  tHgrbg}bvWJ@\B
  [o]
  YsSystemFontCache();
    ftHgRXgN^BftHgtHgi邢́AftHg
    ԋ߂ƎvtHgjgpłԂɏB

  ~YsSystemFontCache();
    fXgN^B


  YSRESULT RequestDefaultFont(void);
    ftHgi܂͑ftHgɈԋ߂ȁjtHg̃rbg}bv
    łԂɂB


  YSRESULT RequestDefaultFontWithHeight(int height);
    ftHgi܂͑ftHgɈԋ߂ȁjtHgɍw肵
    rbg}bv𐶐łԂɂB


  inline YSRESULT MakeRGBABitmap(
      YsSystemFontTextBitmap &bmp,
      const wchar_t wStr[],unsigned 
      int fgCol,const unsigned int bgCol,YSBOOL reverse) const;
    UNICODEwStr\rbg}bv𐶐bmpɃrbg}bvԂB
    fgCol, bgCoĺA24rbgJ[R[h0xRRGGBBtH[}bgB

    reverseYSFALSEw肷ƁAubN̐擪rbg}bv̏[
    ɑΉB

    glDrawPixelsŃrbg}bv\Ƃ́AubN̐擪ŉ
    [ɑΉ̂ŁAreverseYSTRUEw肷BiłȂƏ㉺Ђ
    j


  YSRESULT MakeSingleBitBitmap(
      YsSystemFontTextBitmap &bmp,
      const wchar_t wStr[],YSBOOL reverse) const;
    UNICODEwStr\rbg}bv𐶐bmpɃrbg}bvԂB
    1rbg1sNZɑΉB

    reverseYSFALSEw肷ƁAubN̐擪rbg}bv̏[
    ɑΉB

    glBitmapŎgrbg}bv𐶐ɂ́AreverseYSTRUEw肷B


  YSRESULT MakeRGBABitmap(
      YsSystemFontTextBitmap &bmp,
      const wchar_t wStr[],
      const unsigned char fgCol[3],
      const unsigned char bgCol[3],
      YSBOOL reverse) const;
    UNICODEwStr\rbg}bv𐶐bmpɃrbg}bvԂB
    fgCol, bgCoĺA3oCg24rbgJ[B

    reverseYSFALSEw肷ƁAubN̐擪rbg}bv̏[
    ɑΉB

    glDrawPixelsŃrbg}bv\Ƃ́AubN̐擪ŉ
    [ɑΉ̂ŁAreverseYSTRUEw肷BiłȂƏ㉺Ђ
    j


  YSRESULT MakeGrayScaleAndAlphaBitmap(
      YsSystemFontTextBitmap &bmp,
      const wchar_t wStr[],
      unsigned char fgCol,unsigned char bgCol,YSBOOL reverse) const;

    UNICODEwStr\rbg}bv𐶐bmpɃrbg}bvԂB

    reverseYSFALSEw肷ƁAubN̐擪rbg}bv̏[
    ɑΉB

    glDrawPixelsŃrbg}bv\Ƃ́AubN̐擪ŉ
    [ɑΉ̂ŁAreverseYSTRUEw肷BiłȂƏ㉺Ђ
    j
