コード例 #1
0
ファイル: text_line.cpp プロジェクト: untgames/funner
int main ()
{
  printf ("Results of text_line_test:\n");

  media::FontLibrary font_library;

  TextLine::Pointer text_line (TextLine::Create (font_library));

  printf ("TextLine color = [%.2f %.2f %.2f %.2f]\n", text_line->Color ().x, text_line->Color ().y, text_line->Color ().z, text_line->Color ().w);
  printf ("TextLine text = '%s'\n", text_line->TextUtf8 ());
  printf ("TextLine unicode text = '%S'\n", towstring (*text_line).c_str ());
  printf ("TextLine font name = '%s'\n", text_line->Font ());
  printf ("TextLine length = %u\n", text_line->TextLength ());
  printf ("TextLine horizontal alignment = '%s', vertical_alignment = '%s'\n", get_name (text_line->HorizontalAlignment ()), get_name (text_line->VerticalAlignment ()));
  printf ("textLine spacing multiplier = %.2f\n", text_line->SpacingMultiplier ());

  text_line->SetColor (0.1f, 0.2f, 0.3f, 0.4f);
  text_line->SetTextUtf8 ("Non-unicode text");
  text_line->SetFont  ("font");
  text_line->SetAlignment (TextLineAlignment_Center, TextLineAlignment_Bottom);
  text_line->SetSpacingMultiplier (2.f);

  printf ("TextLine color = [%.2f %.2f %.2f %.2f]\n", text_line->Color ().x, text_line->Color ().y, text_line->Color ().z, text_line->Color ().w);
  printf ("TextLine text = '%s'\n", text_line->TextUtf8 ());
  printf ("TextLine unicode text = '%S'\n", towstring (*text_line).c_str ());
  printf ("TextLine font name = '%s'\n", text_line->Font ());
  printf ("TextLine length = %u\n", text_line->TextLength ());
  printf ("TextLine horizontal alignment = '%s', vertical_alignment = '%s'\n", get_name (text_line->HorizontalAlignment ()), get_name (text_line->VerticalAlignment ()));
  printf ("textLine spacing multiplier = %.2f\n", text_line->SpacingMultiplier ());
  
  stl::basic_string<unsigned int> result = toutf32 (L"Unicode text");

  text_line->SetTextUtf32 (result.c_str (), result.size ());

  printf ("TextLine text = '%s'\n", text_line->TextUtf8 ());
  printf ("TextLine unicode text = '%S'\n", towstring (*text_line).c_str ());
  printf ("TextLine length = %u\n", text_line->TextLength ());

  text_line->SetHorizontalAlignment (TextLineAlignment_Right);
  text_line->SetVerticalAlignment   (TextLineAlignment_Center);

  printf ("TextLine horizontal alignment = '%s', vertical_alignment = '%s'\n", get_name (text_line->HorizontalAlignment ()), get_name (text_line->VerticalAlignment ()));

  text_line->SetHorizontalAlignment (TextLineAlignment_BaseLine);
  text_line->SetVerticalAlignment   (TextLineAlignment_BaseLine);

  printf ("TextLine horizontal alignment = '%s', vertical_alignment = '%s'\n", get_name (text_line->HorizontalAlignment ()), get_name (text_line->VerticalAlignment ()));

  return 0;
}
コード例 #2
0
ファイル: lvm.c プロジェクト: zapline/zlib
void luaV_concat (lua_State *L, int total, int last) {
  int useType = LUA_TSTRING;
  int i;
  StkId top = L->base + last + 1;

  for (i = 0; i < total; ++i)
  {
    if (ttype(top-1-i) == LUA_TSTRING || ttype(top-1-i) == LUA_TWSTRING)
    {
      useType = ttype(top-1-i);
      break;
    }
  }

  if (useType == LUA_TSTRING)
  {
    do {
      StkId top = L->base + last + 1;
      int n = 2;  /* number of elements handled in this pass (at least 2) */
      if (!tostring(L, top-2) || !tostring(L, top-1)) {
        if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
          luaG_concaterror(L, top-2, top-1);
      } else if (tsvalue(top-1)->len > 0) {  /* if len=0, do nothing */
        /* at least two string values; get as many as possible */
        size_t tl = tsvalue(top-1)->len;
        char *buffer;
        int i;
        /* collect total length */
        for (n = 1; n < total && tostring(L, top-n-1); n++) {
          size_t l = tsvalue(top-n-1)->len;
          if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
          tl += l;
        }
        buffer = luaZ_openspace(L, &G(L)->buff, tl);
        tl = 0;
        for (i=n; i>0; i--) {  /* concat all strings */
          size_t l = tsvalue(top-i)->len;
          memcpy(buffer+tl, svalue(top-i), l);
          tl += l;
#if LUA_REFCOUNT
          luarc_cleanvalue(top-i);
#endif /* LUA_REFCOUNT */
        }
        setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
      }
      total -= n-1;  /* got `n' strings to create 1 new */
      last -= n-1;
    } while (total > 1);  /* repeat until only 1 result left */
  } else {
    do {
      StkId top = L->base + last + 1;
      int n = 2;  /* number of elements handled in this pass (at least 2) */
      if (!towstring(L, top-2) || !towstring(L, top-1)) {
        if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
          luaG_concaterror(L, top-2, top-1);
      } else if (tsvalue(top-1)->len > 0) {  /* if len=0, do nothing */
        /* at least two string values; get as many as possible */
        size_t tl = tsvalue(top-1)->len;
        char *buffer;
        int i;
        /* collect total length */
        for (n = 1; n < total && towstring(L, top-n-1); n++) {
          size_t l = tsvalue(top-n-1)->len;
          if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
          tl += l;
        }
        buffer = luaZ_openspace(L, &G(L)->buff, tl*2);
        tl = 0;
        for (i=n; i>0; i--) {  /* concat all strings */
          size_t l = tsvalue(top-i)->len;
          memcpy(buffer+tl*2, wsvalue(top-i), l*2);
          tl += l;
#if LUA_REFCOUNT
          luarc_cleanvalue(top-i);
#endif /* LUA_REFCOUNT */
        }
        setwsvalue2s(L, top-n, luaS_newlwstr(L, (const lua_WChar*)buffer, tl));
      }
      total -= n-1;  /* got `n' strings to create 1 new */
      last -= n-1;
    } while (total > 1);  /* repeat until only 1 result left */
  }
}