void ImageWrapper::NewImage( const v8::FunctionCallbackInfo< v8::Value >& args) { v8::Isolate* isolate = args.GetIsolate(); v8::HandleScope handleScope( isolate); if(!args.IsConstructCall()) { DALI_SCRIPT_EXCEPTION( isolate, "Image constructor called without 'new'"); return; } // find out the callee function name...e.g. BufferImage, ResourceImage v8::Local<v8::Function> callee = args.Callee(); v8::Local<v8::Value> v8String = callee->GetName(); std::string typeName = V8Utils::v8StringToStdString( v8String ); ImageType imageType = GetImageType( typeName ); if( imageType == UNKNOWN_IMAGE_TYPE ) { DALI_SCRIPT_EXCEPTION( isolate, "unknown image type"); return; } Image image = (ImageApiLookup[imageType].constructor)( args ); if( ! image ) { // a v8 exception will have been thrown by the constructor return; } v8::Local<v8::Object> localObject = WrapImage( isolate, image, imageType ); args.GetReturnValue().Set( localObject ); }
v8::Handle<v8::Object> ImageWrapper::WrapImage(v8::Isolate* isolate, const Dali::Image& image ) { v8::EscapableHandleScope handleScope( isolate ); v8::Local<v8::Object> object = WrapImage( isolate, image, GetImageType( image.GetTypeName() ) ); return handleScope.Escape( object ); }
// the formatter's core, wraps the line and justifies it if needed int TextFormatter::WrapLine(CFDC& dc, Paragraph& pp, FilePos& pos, LineArray& la, int top, int maxh) { if (maxh <= 0) return 0; // process images separately if (pp.flags&Paragraph::image) return WrapImage(dc, pp, pos, la, top, maxh); if (pp.len == 0 || (pp.len == 1 && pp.str[0] == L' ')) { dc.SelectFont(0, 0); int fh, fa; dc.GetFontSize(fh, fa); if (fh > maxh) return -1; Line l; l.pos = pos; l.flags = Line::first | Line::last | Line::defstyle; l.height = fh; l.base = fa; la.Add(l); pos.off = pp.len; return l.height; } if (m_hyphenate) pp.Hyphenate(); const wchar_t *str = pp.str; int len = pp.len; Buffer<int> dx(len + 1); int toth = 0; while (toth < maxh && pos.off < len) { // 1. get text size int nch = len; int curwidth = m_width; int ispace = 0; if (pos.off == 0 && (pp.flags&(Paragraph::center | Paragraph::right)) == 0) AdjustIndent(curwidth, ispace, pp.lindent, pp.rindent, pp.findent, dc.GetLPX()); else AdjustIndent(curwidth, ispace, pp.lindent, pp.rindent, 0, dc.GetLPX()); dx[0] = 0; int lh = 1, lbase = 1; GetTextExtent(dc, pp, pos.off, curwidth, nch, dx + 1, lh, lbase); if (toth + lh > maxh) return -1; if (nch == 0) nch = 1; // 2. do word wrap bool addhyp = false; if (nch + pos.off < pp.str.size()) { int i; for (i = nch; i > 0 && str[pos.off + i] != L' '; --i) { // wrap at existing dashes if (i < nch && (str[pos.off + i] == L'-' || str[pos.off + i] == 0x2013 || str[pos.off + i] == 0x2014) && i < len - 1 && (str[pos.off + i + 1] == L' ' || iswalpha(str[pos.off + i + 1]))) { ++i; break; } // or at possible hyphenation points if (m_hyphenate && pp.cflags[pos.off + i].hyphen && dx[i] + dc.GetHypWidth() <= curwidth) { addhyp = true; break; } } if (i > 0) nch = i; else addhyp = false; } // insert it into line list if (pos.off == 0 && nch == pp.str.size()) { // got full line Line l(str, len, false); l.pos = pos; l.flags = Line::first | Line::last; l.ispace = ispace; l.height = lh; l.base = lbase; if (dx[nch] < curwidth) { if (pp.flags&Paragraph::center) l.ispace += (curwidth - dx[nch]) / 2; else if (pp.flags&Paragraph::right) l.ispace += curwidth - dx[nch]; } CopyAttr(l.attr, pp.cflags, len); for (int j = 0; j < len; ++j) l.dx[j] = dx[j + 1] - dx[j]; la.Add(l); pos.off = len; } else { Line l(str + pos.off, nch, addhyp); if (addhyp) l.str[nch] = L'-'; l.pos = pos; l.ispace = ispace; l.height = lh; l.base = lbase; l.flags = 0; if (pos.off == 0) l.flags |= Line::first; if (pos.off + nch == pp.str.size()) l.flags |= Line::last; for (int j = 0; j < nch; ++j) l.dx[j] = dx[j + 1] - dx[j]; int extra_width = 0; if (addhyp) l.dx[nch] = extra_width = dc.GetHypWidth(); // 3. justify/center text if needed if (dx[nch] < curwidth) { if (addhyp) curwidth -= extra_width; if (pp.flags&Paragraph::center) { l.ispace += (curwidth - dx[nch]) / 2; } else if (pp.flags&Paragraph::right) { l.ispace += curwidth - dx[nch]; } else if ((m_justified || pp.flags&Paragraph::justify) && !(l.flags&Line::last)) { // count spaces in string int nspc = 0, i; for (i = 0; i < nch; ++i) if (L' ' == str[pos.off + i]) ++nspc; // and distribute extra width to them if (nspc > 0) { int addw = (curwidth - dx[nch]) / nspc; int extraddw = curwidth - dx[nch] - addw*nspc; for (i = 0; i < nch; ++i) { if (str[pos.off + i] == L' ') { l.dx[i] += addw; if (extraddw) { ++l.dx[i]; --extraddw; } } } } } } CopyAttr(l.attr, pp.cflags + pos.off, nch); if (addhyp) l.attr[nch] = l.attr[nch - 1]; la.Add(l); pos.off += nch; while (pos.off < len && str[pos.off] == L' ') ++pos.off; } toth += lh; } return toth; }