/// <summary>
        /// Get the image stored at the specified path as an IPicture.
        /// The PictureHolder remains responsible to dispose or release the picture as needed,
        /// typically when the application exits, so the client may keep and use it indefinitely.
        /// </summary>
        public IPicture GetComPicture(string imagePath)
        {
            IPicture comPicture;

            if (m_previousPictures == null)
            {
                m_previousPictures = new Dictionary <string, IPicture>();
            }
            if (m_previousPictures.TryGetValue(imagePath, out comPicture))
            {
                return(comPicture);
            }
            try
            {
                string actualFilePath = FileUtils.ActualFilePath(imagePath);
                using (var image = Image.FromFile(actualFilePath))
                {
                    comPicture = (IPicture)OLECvt.ToOLE_IPictureDisp(image);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Failed to create picture from path " + imagePath + " exception: " + e.Message);
                comPicture = null;                 // if we can't get the picture too bad.
            }
            m_previousPictures[imagePath] = comPicture;
            return(comPicture);
        }
Beispiel #2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Prepare an image by replacing the transparent color with the window color.
 /// </summary>
 /// <param name="img"></param>
 /// <returns></returns>
 /// ------------------------------------------------------------------------------------
 private static IPicture PrepareImage(Image img)
 {
     using (var bitmap = ResourceHelper.ReplaceTransparentColor(img, SystemColors.Window))
     {
         return((IPicture)OLECvt.ToOLE_IPictureDisp(bitmap));
     }
 }
Beispiel #3
0
            public SandboxVc(CachePair caches, InterlinLineChoices choices, bool fIconsForAnalysisChoices, SandboxBase sandbox)
            {
                m_caches  = caches;
                m_cache   = caches.MainCache;               //prior to 9-20-2011 this was not set, if we find there was a reason get rid of this.
                m_choices = choices;
                m_sandbox = sandbox;
                m_fIconsForAnalysisChoices = fIconsForAnalysisChoices;
                m_wsAnalysis       = caches.MainCache.DefaultAnalWs;
                m_wsUi             = caches.MainCache.LanguageWritingSystemFactoryAccessor.UserWs;
                m_tssMissingMorphs = TsStringUtils.MakeString(ITextStrings.ksStars, m_sandbox.RawWordformWs);
                m_tssEmptyAnalysis = TsStringUtils.EmptyString(m_wsAnalysis);
                m_tssEmptyVern     = TsStringUtils.EmptyString(m_sandbox.RawWordformWs);
                m_tssMissingEntry  = m_tssMissingMorphs;
                // It's tempting to re-use m_tssMissingMorphs, but the analysis and vernacular default
                // fonts may have different sizes, requiring differnt line heights to align things well.
                m_tssMissingMorphGloss = TsStringUtils.MakeString(ITextStrings.ksStars, m_wsAnalysis);
                m_tssMissingMorphPos   = TsStringUtils.MakeString(ITextStrings.ksStars, m_wsAnalysis);
                m_tssMissingWordPos    = m_tssMissingMorphPos;
                m_PulldownArrowPic     = OLECvt.ConvertImageToComPicture(ResourceHelper.InterlinPopupArrow);
                m_dxmpArrowPicWidth    = ConvertPictureWidthToMillipoints(m_PulldownArrowPic.Picture);
                CoreWritingSystemDefinition wsObj = caches.MainCache.ServiceLocator.WritingSystemManager.Get(m_sandbox.RawWordformWs);

                if (wsObj != null)
                {
                    m_fRtl = wsObj.RightToLeftScript;
                }
            }
Beispiel #4
0
        private IPicture LoadPicture()
        {
            IPicture picture;
            Image    image = null;

            try
            {
                try
                {
                    image = Image.FromFile(FileUtils.ActualFilePath(m_sPath));
                }
                catch
                {
                    // unable to read image. set to default image that indicates an invalid image.
                    image = SimpleRootSite.ImageNotFoundX;
                }
                try
                {
                    picture = (IPicture)OLECvt.ToOLE_IPictureDisp(image);
                }
                catch
                {
                    // conversion to OLE format from current image format is not supported (e.g. WMF file)
                    // try to convert it to a bitmap and convert it to OLE format again.
                    // TODO: deal with transparency
                    // We could just do the following line (creating a new bitmap) instead of going
                    // through a memory stream, but then we end up with an image that is too big.
                    //image = new Bitmap(image, image.Size);
                    using (MemoryStream imageStream = new MemoryStream())
                    {
                        image.Save(imageStream, ImageFormat.Png);
                        image.Dispose();
                        // TODO-Linux: useEmbeddedColorManagement parameter is not supported
                        // on Mono
                        image = Image.FromStream(imageStream, true);
                    }
                    picture = (IPicture)OLECvt.ToOLE_IPictureDisp(image);
                }
                m_width           = picture.Width;
                m_height          = picture.Height;
                m_internalPicture = new WeakReference(picture);
            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                }
            }
            return(picture);
        }
        /// <summary>
        /// Get an IPicture corresponding to the specified key. If one is not known,
        /// obtain it from the source image, and save it for next time. The PictureHolder
        /// remains responsible for disposing or releasing the picture in either case.
        /// </summary>
        public IPicture GetPicture(string key, Image source)
        {
            IPicture comPicture;

            if (m_previousPictures == null)
            {
                m_previousPictures = new Dictionary <string, IPicture>();
            }
            if (!m_previousPictures.TryGetValue(key, out comPicture))
            {
                comPicture = (IPicture)OLECvt.ToOLE_IPictureDisp(source);
                m_previousPictures[key] = comPicture;
            }
            return(comPicture);
        }
Beispiel #6
0
 /// <summary>
 /// Converts the image to (an OLECvt) IPicture picture and wraps it with a disposable object.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <returns></returns>
 static public ComPictureWrapper ConvertImageToComPicture(Image image)
 {
     return(new ComPictureWrapper((IPicture)OLECvt.ToOLE_IPictureDisp(image)));
 }
Beispiel #7
0
 public ImageBox(AssembledStyles styles, Image image) : base(styles)
 {
     BaseImage = image;             // keep a reference to it so it doesn't become garbage
     Picture   = (IPicture)OLECvt.ToOLE_IPictureDisp(image);
 }
Beispiel #8
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Display the specified object (from an ORC embedded in a string). The default
        /// here knows how to display IPictures.
        /// </summary>
        /// <param name="vwenv"></param>
        /// <param name="hvo"></param>
        /// -----------------------------------------------------------------------------------
        public virtual void DisplayEmbeddedObject(IVwEnv vwenv, int hvo)
        {
            CheckDisposed();
            // See if it is a CmPicture.
            ISilDataAccess sda   = vwenv.DataAccess;
            int            clsid = sda.get_IntProp(hvo, (int)CmObjectFields.kflidCmObject_Class);

            if (clsid != CmPicture.kclsidCmPicture)
            {
                return;                 // don't know how to deal with it.
            }
            int hvoFile = sda.get_ObjectProp(hvo, (int)CmPicture.CmPictureTags.kflidPictureFile);

            if (hvoFile == 0)
            {
                return;
            }
            string path;
            string fileName = sda.get_UnicodeProp(hvoFile, (int)CmFile.CmFileTags.kflidInternalPath);

            if (Path.IsPathRooted(fileName))
            {
                path = fileName;
            }
            else
            {
                if (m_hvoLangProject == 0)
                {
                    TryToSetLangProjectHvo(sda, hvo);
                }
                string externalRoot = sda.get_UnicodeProp(m_hvoLangProject, (int)LangProject.LangProjectTags.kflidExtLinkRootDir);
                if (String.IsNullOrEmpty(externalRoot))
                {
                    path = Path.Combine(DirectoryFinder.FWDataDirectory, fileName);
                }
                else
                {
                    path = Path.Combine(externalRoot, fileName);
                }
            }
            vwenv.set_IntProperty((int)FwTextPropType.ktptAlign,
                                  (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
            Image image;

            try
            {
                image = Image.FromFile(FileUtils.ActualFilePath(path));
            }
            catch
            {
                // unable to read image. set to default image that indicates an invalid image.
                image = ResourceHelper.ImageNotFoundX;
            }
            stdole.IPicture picture;
            try
            {
                picture = (stdole.IPicture)OLECvt.ToOLE_IPictureDisp(image);
            }
            catch
            {
                // conversion to OLE format from current image format is not supported (e.g. WMF file)
                // try to convert it to a bitmap and convert it to OLE format again.
                // TODO: deal with transparency
                // We could just do the following line (creating a new bitmap) instead of going
                // through a memory stream, but then we end up with an image that is too big.
                //image = new Bitmap(image, image.Size);
                using (MemoryStream imageStream = new MemoryStream())
                {
                    image.Save(imageStream, ImageFormat.Png);
                    image = Image.FromStream(imageStream, true);
                }
                picture = (stdole.IPicture)OLECvt.ToOLE_IPictureDisp(image);
            }
            // -1 is ktagNotAnAttr. 0 width & height mean use natural width/height.
            vwenv.AddPictureWithCaption(picture, -1, CaptionProps, hvoFile, m_wsDefault, 0, 0, this);
            image.Dispose();
        }
Beispiel #9
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Prepare an image by replacing the transparent color with the window color.
 /// </summary>
 /// <param name="img"></param>
 /// <returns></returns>
 /// ------------------------------------------------------------------------------------
 private stdole.IPicture PrepareImage(Image img)
 {
     return((stdole.IPicture)OLECvt.ToOLE_IPictureDisp(
                ResourceHelper.ReplaceTransparentColor(img, SystemColors.Window)));
 }