Dictionary Services Reference
| Derived from | |
| Framework | CoreServices/CoreServices.h, Carbon/Carbon.h |
| Companion guide | |
| Declared in | DictionaryServices.h MacApplication.h |
Overview
Dictionary Services provides functions that let you access dictionaries programmatically from within your application. There are three functions described in this reference. Two of them are defined in the Core Services framework; the third is defined in the Carbon framework.
A dictionary is any look-up reference that is built using the Dictionary Development Kit. The contents of a dictionary can serve many purposes. The most typical use is to provide definitions for a single language, but you can create content for a thesaurus, bilingual dictionaries (such as English-Japanese), in-house glossaries, and professional dictionaries (such as legal, medical, and technical).
Functions by Task
Searching Dictionaries
Displaying Dictionary Results
Functions
DCSCopyTextDefinition
Returns the definition associated with the provided text range.
CFStringRef DCSCopyTextDefinition ( DCSDictionaryRef dictionary, CFStringRef textString, CFRange range );
Parameters
- dictionary
This parameter is reserved for future use, so pass
NULL. Dictionary Services searches in all active dictionaries.- textString
Text that contains the word or phrase to look up.
- range
A range that specifies the location of the word or phrase in the
textStringparameter. If text string exactly specifies the word or phrase that you want to look up, you can pass the range of the text string. For example, for the wordmake, you would pass (0,4) to specify the range.If the
textStringparameter contains the word or phrase, but does not specify it exactly, then pass the range returned by the functionDCSGetTermRangeInString.
Return Value
The definition of the word or phrase, as plain text. The returned text does not contain any elements that are marked with a priority attribute whose value is 2.
Discussion
This function returns the description of the first matching record found in the the active dictionaries. It searches first in the default word definition dictionary which, in the English environment, is the Oxford dictionary.
Availability
- Available in OS X v10.5 and later.
Declared In
DictionaryServices.hDCSGetTermRangeInString
Determines the range of the longest word or phrase with respect to an offset.
CFRange DCSGetTermRangeInString ( DCSDictionaryRef dictionary, CFStringRef textString, CFIndex offset );
Parameters
- dictionary
This parameter is reserved for future use, so pass
NULL. Dictionary Services searches in all active dictionaries.- textString
Text that contains the word or phrase to look up.
- offset
A character offset in the
textStringparameter.
Return Value
The range that specifies the location, around the specified offset, of the word or phrase , or the constant kCFNotFound.
Discussion
You can use this function to determine the range of text that contains a word or phrase. After you determine the range, you can pass the result to the functions DCSCopyTextDefinition and HIDictionaryWindowShow.
To see how this works, follow these steps:
In OS X v10.5 or later, open Text Edit.
Type
It is a foggy day in San Francisco, California.Control-click
Francisco(don’t select it). Then, choose “Lookup in Dictionary”.
Note that the Dictionary window appears with a definition of San Francisco. The function DCSGetTermRangeInString automatically detected the range of the phrase San Francisco, using Francisco as the text string to search for and a character offset in this string. The function expanded the range until it found a possible match.
You can also point the cursor at the word Francisco and, without making a selection or clicking, type Command-Control-D. DCSGetTermRangeInString detects the range.
The function DCSGetTermRangeInString only returns the range. You must call DCSCopyTextDefinition to copy the definition and HIDictionaryWindowShow to display the definition in a Dictionary window.
Availability
- Available in OS X v10.5 and later.
Declared In
DictionaryServices.hHIDictionaryWindowShow
Displays dictionary search result in a dictionary window.
void HIDictionaryWindowShow( DCSDictionaryRef dictionary, CFTypeRef textString, CFRange selectionRange, CTFontRef textFont, CGPoint textOrigin, Boolean verticalText, const CGAffineTransform *viewTransform );
Parameters
- dictionary
This parameter is reserved for future use, so pass
NULL. Dictionary Services searches in all active dictionaries.- textString
Text that contains the word or phrase to look up specified as one of the following: a
CFStringobject, aCFAttributedStringobject, or aCFDataobject that contains text in Rich Text Format. Dictionary Services uses the text attributes to draw the title of the dictionary window. If you provide the text string as aCFStringobject, you must also provide a display font in thetextFontparameter.- selectionRange
If you are using this function to show the results associated with text selected by the user, then provide the selection range of the
textStringparameter. If you are using this function to show the results associated with calling theDCSGetTermRangeInStringfunction, then provide the range returned by that function.- textFont
The Core Text font to use for the title of the dictionary window. You must provide a font only when the
textStringparameter is aCFStringobject; otherwise Dictionary Services ignores this parameter.- textOrigin
The origin, in screen pixels, of the typographic baseline of the characters specified by the
selectionRangeparameter. The top left of the screen is (0,0).- verticalText
This parameter is reserved for future use. Dictionary Services draws the text in a horizontal orientation regardless of whether you pass
trueorfalse.- viewTransform
The affine transformation matrix to apply to the window that contains the text string. Pass
NULLto use the identity matrix. Use this to align the dictionary window with the original text. You can only apply a scaling transform; you cannot apply other types of transformations.
Discussion
This function opens a window to display the definition of a word or phrase.
Availability
- Available in OS X v10.5 and later.
Declared In
MacApplication.hData Types
DCSDictionaryRef
An opaque object that represents a dictionary file.
typedef const struct __DCSDictionary* DCSDictionaryRef;
Discussion
This data type is reserved for future use.
Availability
- Available in OS X v10.5 and later.
Declared In
DictionaryServices.h© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-05-29)